home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2013 July / PCgo_CD_v2_13_07.iso / nw.pak / Unnamed File 000653.unknown < prev    next >
Encoding:
Text File  |  2012-12-14  |  133.8 KB  |  4,818 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. WebInspector.CSSNamedFlowCollectionsView = function()
  8. {
  9. WebInspector.SidebarView.call(this, WebInspector.SidebarView.SidebarPosition.Left);
  10. this.registerRequiredCSS("cssNamedFlows.css");
  11.  
  12. this._namedFlows = {};
  13. this._contentNodes = {};
  14. this._regionNodes = {};
  15.  
  16. this.element.addStyleClass("css-named-flow-collections-view");
  17. this.element.addStyleClass("fill");
  18.  
  19. this._statusElement = document.createElement("span");
  20. this._statusElement.textContent = WebInspector.UIString("CSS Named Flows");
  21.  
  22. var sidebarHeader = this._leftElement.createChild("div", "tabbed-pane-header selected sidebar-header")
  23. var tab = sidebarHeader.createChild("div", "tabbed-pane-header-tab");
  24. tab.createChild("span", "tabbed-pane-header-tab-title").textContent = WebInspector.UIString("CSS Named Flows");
  25.  
  26. this._sidebarContentElement = this._leftElement.createChild("div", "sidebar-content outline-disclosure");
  27. this._flowListElement = this._sidebarContentElement.createChild("ol");
  28. this._flowTree = new TreeOutline(this._flowListElement);
  29.  
  30. this._emptyElement = document.createElement("div");
  31. this._emptyElement.addStyleClass("info");
  32. this._emptyElement.textContent = WebInspector.UIString("No CSS Named Flows");
  33.  
  34. this._tabbedPane = new WebInspector.TabbedPane();
  35. this._tabbedPane.closeableTabs = true;
  36. this._tabbedPane.show(this._rightElement);
  37. }
  38.  
  39. WebInspector.CSSNamedFlowCollectionsView.prototype = {
  40. showInDrawer: function()
  41. {
  42. WebInspector.showViewInDrawer(this._statusElement, this);
  43. },
  44.  
  45. reset: function()
  46. {
  47. if (!this._document)
  48. return;
  49.  
  50. WebInspector.cssModel.getNamedFlowCollectionAsync(this._document.id, this._resetNamedFlows.bind(this));
  51. },
  52.  
  53.  
  54. _setDocument: function(document)
  55. {
  56. this._document = document;
  57. this.reset();
  58. },
  59.  
  60.  
  61. _documentUpdated: function(event)
  62. {
  63. var document =   (event.data);
  64. this._setDocument(document);
  65. },
  66.  
  67.  
  68. _setSidebarHasContent: function(hasContent)
  69. {
  70. if (hasContent) {
  71. if (!this._emptyElement.parentNode)
  72. return;
  73.  
  74. this._sidebarContentElement.removeChild(this._emptyElement);
  75. this._sidebarContentElement.appendChild(this._flowListElement);
  76. } else {
  77. if (!this._flowListElement.parentNode)
  78. return;
  79.  
  80. this._sidebarContentElement.removeChild(this._flowListElement);
  81. this._sidebarContentElement.appendChild(this._emptyElement);
  82. }
  83. },
  84.  
  85.  
  86. _appendNamedFlow: function(flow)
  87. {
  88. var flowHash = this._hashNamedFlow(flow.documentNodeId, flow.name);
  89. var flowContainer = { flow: flow, flowHash: flowHash };
  90.  
  91. for (var i = 0; i < flow.content.length; ++i)
  92. this._contentNodes[flow.content[i]] = flowHash;
  93. for (var i = 0; i < flow.regions.length; ++i)
  94. this._regionNodes[flow.regions[i].nodeId] = flowHash;
  95.  
  96. var flowTreeItem = new WebInspector.FlowTreeElement(flowContainer);
  97. flowTreeItem.onselect = this._selectNamedFlowTab.bind(this, flowHash);
  98.  
  99. flowContainer.flowTreeItem = flowTreeItem;
  100. this._namedFlows[flowHash] = flowContainer;
  101.  
  102. if (!this._flowTree.children.length)
  103. this._setSidebarHasContent(true);
  104. this._flowTree.appendChild(flowTreeItem);
  105. },
  106.  
  107.  
  108. _removeNamedFlow: function(flowHash)
  109. {
  110. var flowContainer = this._namedFlows[flowHash];
  111.  
  112. if (this._tabbedPane._tabsById[flowHash])
  113. this._tabbedPane.closeTab(flowHash);
  114. this._flowTree.removeChild(flowContainer.flowTreeItem);
  115.  
  116. var flow = flowContainer.flow;
  117. for (var i = 0; i < flow.content.length; ++i)
  118. delete this._contentNodes[flow.content[i]];
  119. for (var i = 0; i < flow.regions.length; ++i)
  120. delete this._regionNodes[flow.regions[i].nodeId];
  121.  
  122. delete this._namedFlows[flowHash];
  123.  
  124. if (!this._flowTree.children.length)
  125. this._setSidebarHasContent(false);
  126. },
  127.  
  128.  
  129. _updateNamedFlow: function(flow)
  130. {
  131. var flowHash = this._hashNamedFlow(flow.documentNodeId, flow.name);
  132. var flowContainer = this._namedFlows[flowHash];
  133.  
  134. if (!flowContainer)
  135. return;
  136.  
  137. var oldFlow = flowContainer.flow;
  138. flowContainer.flow = flow;
  139.  
  140. for (var i = 0; i < oldFlow.content.length; ++i)
  141. delete this._contentNodes[oldFlow.content[i]];
  142. for (var i = 0; i < oldFlow.regions.length; ++i)
  143. delete this._regionNodes[oldFlow.regions[i].nodeId];
  144.  
  145. for (var i = 0; i < flow.content.length; ++i)
  146. this._contentNodes[flow.content[i]] = flowHash;
  147. for (var i = 0; i < flow.regions.length; ++i)
  148. this._regionNodes[flow.regions[i].nodeId] = flowHash;
  149.  
  150. flowContainer.flowTreeItem.setOverset(flow.overset);
  151.  
  152. if (flowContainer.flowView)
  153. flowContainer.flowView.flow = flow;
  154. },
  155.  
  156.  
  157. _resetNamedFlows: function(namedFlowCollection)
  158. {
  159. for (var flowHash in this._namedFlows)
  160. this._removeNamedFlow(flowHash);
  161.  
  162. var namedFlows = namedFlowCollection.namedFlowMap;
  163. for (var flowName in namedFlows)
  164. this._appendNamedFlow(namedFlows[flowName]);
  165.  
  166. if (!this._flowTree.children.length)
  167. this._setSidebarHasContent(false);
  168. else
  169. this._showNamedFlowForNode(WebInspector.panel("elements").treeOutline.selectedDOMNode());
  170. },
  171.  
  172.  
  173. _namedFlowCreated: function(event)
  174. {
  175.  
  176. if (event.data.documentNodeId !== this._document.id)
  177. return;
  178.  
  179. var flow =   (event.data);
  180. this._appendNamedFlow(flow);
  181. },
  182.  
  183.  
  184. _namedFlowRemoved: function(event)
  185. {
  186.  
  187. if (event.data.documentNodeId !== this._document.id)
  188. return;
  189.  
  190. this._removeNamedFlow(this._hashNamedFlow(event.data.documentNodeId, event.data.flowName));
  191. },
  192.  
  193.  
  194. _regionLayoutUpdated: function(event)
  195. {
  196.  
  197. if (event.data.documentNodeId !== this._document.id)
  198. return;
  199.  
  200. var flow =   (event.data);
  201. this._updateNamedFlow(flow);
  202. },
  203.  
  204.  
  205. _hashNamedFlow: function(documentNodeId, flowName)
  206. {
  207. return documentNodeId + "|" + flowName;
  208. },
  209.  
  210.  
  211. _showNamedFlow: function(flowHash)
  212. {
  213. this._selectNamedFlowInSidebar(flowHash);
  214. this._selectNamedFlowTab(flowHash);
  215. },
  216.  
  217.  
  218. _selectNamedFlowInSidebar: function(flowHash)
  219. {
  220. this._namedFlows[flowHash].flowTreeItem.select(true);
  221. },
  222.  
  223.  
  224. _selectNamedFlowTab: function(flowHash)
  225. {
  226. var flowContainer = this._namedFlows[flowHash];
  227.  
  228. if (this._tabbedPane.selectedTabId === flowHash)
  229. return;
  230.  
  231. if (!this._tabbedPane.selectTab(flowHash)) {
  232. if (!flowContainer.flowView)
  233. flowContainer.flowView = new WebInspector.CSSNamedFlowView(flowContainer.flow);
  234.  
  235. this._tabbedPane.appendTab(flowHash, flowContainer.flow.name, flowContainer.flowView);
  236. this._tabbedPane.selectTab(flowHash);
  237. }
  238. },
  239.  
  240.  
  241. _selectedNodeChanged: function(event)
  242. {
  243. var node =   (event.data);
  244. this._showNamedFlowForNode(node);
  245. },
  246.  
  247.  
  248. _tabSelected: function(event)
  249. {
  250. this._selectNamedFlowInSidebar(event.data.tabId);
  251. },
  252.  
  253.  
  254. _tabClosed: function(event)
  255. {
  256. this._namedFlows[event.data.tabId].flowTreeItem.deselect();
  257. },
  258.  
  259.  
  260. _showNamedFlowForNode: function(node)
  261. {
  262. if (!node)
  263. return;
  264.  
  265. if (this._regionNodes[node.id]) {
  266. this._showNamedFlow(this._regionNodes[node.id]);
  267. return;
  268. }
  269.  
  270. while (node) {
  271. if (this._contentNodes[node.id]) {
  272. this._showNamedFlow(this._contentNodes[node.id]);
  273. return;
  274. }
  275.  
  276. node = node.parentNode;
  277. }
  278. },
  279.  
  280. wasShown: function()
  281. {
  282. WebInspector.SidebarView.prototype.wasShown.call(this);
  283.  
  284. WebInspector.domAgent.requestDocument(this._setDocument.bind(this));
  285.  
  286. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdated, this);
  287.  
  288. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.NamedFlowCreated, this._namedFlowCreated, this);
  289. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.NamedFlowRemoved, this._namedFlowRemoved, this);
  290. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.RegionLayoutUpdated, this._regionLayoutUpdated, this);
  291.  
  292. WebInspector.panel("elements").treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
  293.  
  294. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  295. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
  296. },
  297.  
  298. willHide: function()
  299. {
  300. WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdated, this);
  301.  
  302. WebInspector.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.NamedFlowCreated, this._namedFlowCreated, this);
  303. WebInspector.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.NamedFlowRemoved, this._namedFlowRemoved, this);
  304. WebInspector.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.RegionLayoutUpdated, this._regionLayoutUpdated, this);
  305.  
  306. WebInspector.panel("elements").treeOutline.removeEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
  307.  
  308. this._tabbedPane.removeEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  309. this._tabbedPane.removeEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
  310. },
  311.  
  312. __proto__: WebInspector.SidebarView.prototype
  313. }
  314.  
  315.  
  316. WebInspector.FlowTreeElement = function(flowContainer)
  317. {
  318. var container = document.createElement("div");
  319. container.createChild("div", "selection");
  320. container.createChild("span", "title").createChild("span").textContent = flowContainer.flow.name;
  321.  
  322. TreeElement.call(this, container, flowContainer, false);
  323.  
  324. this._overset = false;
  325. this.setOverset(flowContainer.flow.overset);
  326. }
  327.  
  328. WebInspector.FlowTreeElement.prototype = {
  329.  
  330. setOverset: function(newOverset)
  331. {
  332. if (this._overset === newOverset)
  333. return;
  334.  
  335. if (newOverset) {
  336. this.title.addStyleClass("named-flow-overflow");
  337. this.tooltip = WebInspector.UIString("Overflows.");
  338. } else {
  339. this.title.removeStyleClass("named-flow-overflow");
  340. this.tooltip = "";
  341. }
  342.  
  343. this._overset = newOverset;
  344. },
  345.  
  346. __proto__: TreeElement.prototype
  347. }
  348. ;
  349.  
  350.  
  351.  
  352. WebInspector.CSSNamedFlowView = function(flow)
  353. {
  354. WebInspector.View.call(this);
  355. this.element.addStyleClass("css-named-flow");
  356. this.element.addStyleClass("outline-disclosure");
  357.  
  358. this._treeOutline = new TreeOutline(this.element.createChild("ol"), true);
  359.  
  360. this._contentTreeItem = new TreeElement(WebInspector.UIString("content"), null, true);
  361. this._treeOutline.appendChild(this._contentTreeItem);
  362.  
  363. this._regionsTreeItem = new TreeElement(WebInspector.UIString("region chain"), null, true);
  364. this._regionsTreeItem.expand();
  365. this._treeOutline.appendChild(this._regionsTreeItem);
  366.  
  367. this._flow = flow;
  368.  
  369. var content = flow.content;
  370. for (var i = 0; i < content.length; ++i)
  371. this._insertContentNode(content[i]);
  372.  
  373. var regions = flow.regions;
  374. for (var i = 0; i < regions.length; ++i)
  375. this._insertRegion(regions[i]);
  376. }
  377.  
  378. WebInspector.CSSNamedFlowView.OversetTypeMessageMap = {
  379. empty: "empty",
  380. fit: "fit",
  381. overset: "overset"
  382. }
  383.  
  384. WebInspector.CSSNamedFlowView.prototype = {
  385.  
  386. _createFlowTreeOutline: function(rootDOMNode)
  387. {
  388. if (!rootDOMNode)
  389. return null;
  390.  
  391. var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
  392. treeOutline.element.addStyleClass("named-flow-element");
  393. treeOutline.setVisible(true);
  394. treeOutline.rootDOMNode = rootDOMNode;
  395. treeOutline.wireToDomAgent();
  396. WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, treeOutline._elementsTreeUpdater._documentUpdated, treeOutline._elementsTreeUpdater);
  397.  
  398. return treeOutline;
  399. },
  400.  
  401.  
  402. _insertContentNode: function(contentNodeId, index)
  403. {
  404. var treeOutline = this._createFlowTreeOutline(WebInspector.domAgent.nodeForId(contentNodeId));
  405. var treeItem = new TreeElement(treeOutline.element, treeOutline);
  406.  
  407. if (index === undefined) {
  408. this._contentTreeItem.appendChild(treeItem);
  409. return;
  410. }
  411.  
  412. this._contentTreeItem.insertChild(treeItem, index);
  413. },
  414.  
  415.  
  416. _insertRegion: function(region, index)
  417. {
  418. var treeOutline = this._createFlowTreeOutline(WebInspector.domAgent.nodeForId(region.nodeId));
  419. treeOutline.element.addStyleClass("region-" + region.regionOverset);
  420.  
  421. var treeItem = new TreeElement(treeOutline.element, treeOutline);
  422. var oversetText = WebInspector.UIString(WebInspector.CSSNamedFlowView.OversetTypeMessageMap[region.regionOverset]);
  423. treeItem.tooltip = WebInspector.UIString("Region is %s.", oversetText);
  424.  
  425. if (index === undefined) {
  426. this._regionsTreeItem.appendChild(treeItem);
  427. return;
  428. }
  429.  
  430. this._regionsTreeItem.insertChild(treeItem, index);
  431. },
  432.  
  433. get flow()
  434. {
  435. return this._flow;
  436. },
  437.  
  438. set flow(newFlow)
  439. {
  440. this._update(newFlow);
  441. },
  442.  
  443.  
  444. _updateRegionOverset: function(regionTreeItem, newRegionOverset, oldRegionOverset)
  445. {
  446. var element = regionTreeItem.representedObject.element;
  447. element.removeStyleClass("region-" + oldRegionOverset);
  448. element.addStyleClass("region-" + newRegionOverset);
  449.  
  450. var oversetText = WebInspector.UIString(WebInspector.CSSNamedFlowView.OversetTypeMessageMap[newRegionOverset]);
  451. regionTreeItem.tooltip = WebInspector.UIString("Region is %s." , oversetText);
  452. },
  453.  
  454.  
  455. _mergeContentNodes: function(oldContent, newContent)
  456. {
  457. var nodeIdSet = {};
  458. for (var i = 0; i < newContent.length; ++i)
  459. nodeIdSet[newContent[i]] = true;
  460.  
  461. var oldContentIndex = 0;
  462. var newContentIndex = 0;
  463. var contentTreeChildIndex = 0;
  464.  
  465. while(oldContentIndex < oldContent.length || newContentIndex < newContent.length) {
  466. if (oldContentIndex === oldContent.length) {
  467. this._insertContentNode(newContent[newContentIndex]);
  468. ++newContentIndex;
  469. continue;
  470. }
  471.  
  472. if (newContentIndex === newContent.length) {
  473. this._contentTreeItem.removeChildAtIndex(contentTreeChildIndex);
  474. ++oldContentIndex;
  475. continue;
  476. }
  477.  
  478. if (oldContent[oldContentIndex] === newContent[newContentIndex]) {
  479. ++oldContentIndex;
  480. ++newContentIndex;
  481. ++contentTreeChildIndex;
  482. continue;
  483. }
  484.  
  485. if (nodeIdSet[oldContent[oldContentIndex]]) {
  486. this._insertContentNode(newContent[newContentIndex], contentTreeChildIndex);
  487. ++newContentIndex;
  488. ++contentTreeChildIndex;
  489. continue;
  490. }
  491.  
  492. this._contentTreeItem.removeChildAtIndex(contentTreeChildIndex);
  493. ++oldContentIndex;
  494. }
  495. },
  496.  
  497.  
  498. _mergeRegions: function(oldRegions, newRegions)
  499. {
  500. var nodeIdSet = {};
  501. for (var i = 0; i < newRegions.length; ++i)
  502. nodeIdSet[newRegions[i].nodeId] = true;
  503.  
  504. var oldRegionsIndex = 0;
  505. var newRegionsIndex = 0;
  506. var regionsTreeChildIndex = 0;
  507.  
  508. while(oldRegionsIndex < oldRegions.length || newRegionsIndex < newRegions.length) {
  509. if (oldRegionsIndex === oldRegions.length) {
  510. this._insertRegion(newRegions[newRegionsIndex]);
  511. ++newRegionsIndex;
  512. continue;
  513. }
  514.  
  515. if (newRegionsIndex === newRegions.length) {
  516. this._regionsTreeItem.removeChildAtIndex(regionsTreeChildIndex);
  517. ++oldRegionsIndex;
  518. continue;
  519. }
  520.  
  521. if (oldRegions[oldRegionsIndex].nodeId === newRegions[newRegionsIndex].nodeId) {
  522. if (oldRegions[oldRegionsIndex].regionOverset !== newRegions[newRegionsIndex].regionOverset)
  523. this._updateRegionOverset(this._regionsTreeItem.children[regionsTreeChildIndex], newRegions[newRegionsIndex].regionOverset, oldRegions[oldRegionsIndex].regionOverset);
  524. ++oldRegionsIndex;
  525. ++newRegionsIndex;
  526. ++regionsTreeChildIndex;
  527. continue;
  528. }
  529.  
  530. if (nodeIdSet[oldRegions[oldRegionsIndex].nodeId]) {
  531. this._insertRegion(newRegions[newRegionsIndex], regionsTreeChildIndex);
  532. ++newRegionsIndex;
  533. ++regionsTreeChildIndex;
  534. continue;
  535. }
  536.  
  537. this._regionsTreeItem.removeChildAtIndex(regionsTreeChildIndex);
  538. ++oldRegionsIndex;
  539. }
  540. },
  541.  
  542.  
  543. _update: function(newFlow)
  544. {
  545. this._mergeContentNodes(this._flow.content, newFlow.content);
  546. this._mergeRegions(this._flow.regions, newFlow.regions);
  547.  
  548. this._flow = newFlow;
  549. },
  550.  
  551. __proto__: WebInspector.View.prototype
  552. }
  553. ;
  554.  
  555.  
  556.  
  557. WebInspector.EventListenersSidebarPane = function()
  558. {
  559. WebInspector.SidebarPane.call(this, WebInspector.UIString("Event Listeners"));
  560. this.bodyElement.addStyleClass("events-pane");
  561.  
  562. this.sections = [];
  563.  
  564. this.settingsSelectElement = document.createElement("select");
  565. this.settingsSelectElement.className = "select-filter";
  566.  
  567. var option = document.createElement("option");
  568. option.value = "all";
  569. option.label = WebInspector.UIString("All Nodes");
  570. this.settingsSelectElement.appendChild(option);
  571.  
  572. option = document.createElement("option");
  573. option.value = "selected";
  574. option.label = WebInspector.UIString("Selected Node Only");
  575. this.settingsSelectElement.appendChild(option);
  576.  
  577. var filter = WebInspector.settings.eventListenersFilter.get();
  578. if (filter === "all")
  579. this.settingsSelectElement[0].selected = true;
  580. else if (filter === "selected")
  581. this.settingsSelectElement[1].selected = true;
  582. this.settingsSelectElement.addEventListener("click", function(event) { event.consume() }, false);
  583. this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
  584.  
  585. this.titleElement.appendChild(this.settingsSelectElement);
  586.  
  587. this._linkifier = new WebInspector.Linkifier();
  588. }
  589.  
  590. WebInspector.EventListenersSidebarPane._objectGroupName = "event-listeners-sidebar-pane";
  591.  
  592. WebInspector.EventListenersSidebarPane.prototype = {
  593. update: function(node)
  594. {
  595. RuntimeAgent.releaseObjectGroup(WebInspector.EventListenersSidebarPane._objectGroupName);
  596. this._linkifier.reset();
  597.  
  598. var body = this.bodyElement;
  599. body.removeChildren();
  600. this.sections = [];
  601.  
  602. var self = this;
  603. function callback(error, eventListeners) {
  604. if (error)
  605. return;
  606.  
  607. var selectedNodeOnly = "selected" === WebInspector.settings.eventListenersFilter.get();
  608. var sectionNames = [];
  609. var sectionMap = {};
  610. for (var i = 0; i < eventListeners.length; ++i) {
  611. var eventListener = eventListeners[i];
  612. if (selectedNodeOnly && (node.id !== eventListener.nodeId))
  613. continue;
  614. eventListener.node = WebInspector.domAgent.nodeForId(eventListener.nodeId);
  615. delete eventListener.nodeId; 
  616. if (/^function _inspectorCommandLineAPI_logEvent\(/.test(eventListener.handlerBody.toString()))
  617. continue; 
  618. var type = eventListener.type;
  619. var section = sectionMap[type];
  620. if (!section) {
  621. section = new WebInspector.EventListenersSection(type, node.id, self._linkifier);
  622. sectionMap[type] = section;
  623. sectionNames.push(type);
  624. self.sections.push(section);
  625. }
  626. section.addListener(eventListener);
  627. }
  628.  
  629. if (sectionNames.length === 0) {
  630. var div = document.createElement("div");
  631. div.className = "info";
  632. div.textContent = WebInspector.UIString("No Event Listeners");
  633. body.appendChild(div);
  634. return;
  635. }
  636.  
  637. sectionNames.sort();
  638. for (var i = 0; i < sectionNames.length; ++i) {
  639. var section = sectionMap[sectionNames[i]];
  640. body.appendChild(section.element);
  641. }
  642. }
  643.  
  644. if (node)
  645. node.eventListeners(callback);
  646. this._selectedNode = node;
  647. },
  648.  
  649. willHide: function()
  650. {
  651. delete this._selectedNode;
  652. },
  653.  
  654. _changeSetting: function()
  655. {
  656. var selectedOption = this.settingsSelectElement[this.settingsSelectElement.selectedIndex];
  657. WebInspector.settings.eventListenersFilter.set(selectedOption.value);
  658. this.update(this._selectedNode);
  659. },
  660.  
  661. __proto__: WebInspector.SidebarPane.prototype
  662. }
  663.  
  664.  
  665. WebInspector.EventListenersSection = function(title, nodeId, linkifier)
  666. {
  667. this.eventListeners = [];
  668. this._nodeId = nodeId;
  669. this._linkifier = linkifier;
  670. WebInspector.PropertiesSection.call(this, title);
  671.  
  672.  
  673. this.propertiesElement.parentNode.removeChild(this.propertiesElement);
  674. delete this.propertiesElement;
  675. delete this.propertiesTreeOutline;
  676.  
  677. this._eventBars = document.createElement("div");
  678. this._eventBars.className = "event-bars";
  679. this.element.appendChild(this._eventBars);
  680. }
  681.  
  682. WebInspector.EventListenersSection.prototype = {
  683. addListener: function(eventListener)
  684. {
  685. var eventListenerBar = new WebInspector.EventListenerBar(eventListener, this._nodeId, this._linkifier);
  686. this._eventBars.appendChild(eventListenerBar.element);
  687. },
  688.  
  689. __proto__: WebInspector.PropertiesSection.prototype
  690. }
  691.  
  692.  
  693. WebInspector.EventListenerBar = function(eventListener, nodeId, linkifier)
  694. {
  695. WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
  696.  
  697. this.eventListener = eventListener;
  698. this._nodeId = nodeId;
  699. this._setNodeTitle();
  700. this._setFunctionSubtitle(linkifier);
  701. this.editable = false;
  702. this.element.className = "event-bar";  
  703. this.headerElement.addStyleClass("source-code");
  704. this.propertiesElement.className = "event-properties properties-tree source-code";  
  705. }
  706.  
  707. WebInspector.EventListenerBar.prototype = {
  708. update: function()
  709. {
  710. function updateWithNodeObject(nodeObject)
  711. {
  712. var properties = [];
  713.  
  714. if (this.eventListener.type)
  715. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("type", this.eventListener.type));
  716. if (typeof this.eventListener.useCapture !== "undefined")
  717. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("useCapture", this.eventListener.useCapture));
  718. if (typeof this.eventListener.isAttribute !== "undefined")
  719. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("isAttribute", this.eventListener.isAttribute));
  720. if (nodeObject)
  721. properties.push(new WebInspector.RemoteObjectProperty("node", nodeObject));
  722. if (typeof this.eventListener.handlerBody !== "undefined")
  723. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("listenerBody", this.eventListener.handlerBody));
  724. if (this.eventListener.sourceName)
  725. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("sourceName", this.eventListener.sourceName));
  726. if (this.eventListener.location)
  727. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("lineNumber", this.eventListener.location.lineNumber + 1));
  728.  
  729. this.updateProperties(properties);
  730. }
  731. WebInspector.RemoteObject.resolveNode(this.eventListener.node, WebInspector.EventListenersSidebarPane._objectGroupName, updateWithNodeObject.bind(this));
  732. },
  733.  
  734. _setNodeTitle: function()
  735. {
  736. var node = this.eventListener.node;
  737. if (!node)
  738. return;
  739.  
  740. if (node.nodeType() === Node.DOCUMENT_NODE) {
  741. this.titleElement.textContent = "document";
  742. return;
  743. }
  744.  
  745. if (node.id === this._nodeId) {
  746. this.titleElement.textContent = node.appropriateSelectorFor();
  747. return;
  748. }
  749.  
  750. this.titleElement.removeChildren();
  751. this.titleElement.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeReference(this.eventListener.node));
  752. },
  753.  
  754. _setFunctionSubtitle: function(linkifier)
  755. {
  756.  
  757. if (this.eventListener.location) {
  758. this.subtitleElement.removeChildren();
  759. var urlElement;
  760. if (this.eventListener.location.scriptId)
  761. urlElement = linkifier.linkifyRawLocation(this.eventListener.location);
  762. if (!urlElement) {
  763. var url = this.eventListener.sourceName;
  764. var lineNumber = this.eventListener.location.lineNumber;
  765. var columnNumber = 0;
  766. urlElement = linkifier.linkifyLocation(url, lineNumber, columnNumber);
  767. }
  768. this.subtitleElement.appendChild(urlElement);
  769. } else {
  770. var match = this.eventListener.handlerBody.match(/function ([^\(]+?)\(/);
  771. if (match)
  772. this.subtitleElement.textContent = match[1];
  773. else
  774. this.subtitleElement.textContent = WebInspector.UIString("(anonymous function)");
  775. }
  776. },
  777.  
  778. __proto__: WebInspector.ObjectPropertiesSection.prototype
  779. }
  780. ;
  781.  
  782.  
  783.  
  784. WebInspector.MetricsSidebarPane = function()
  785. {
  786. WebInspector.SidebarPane.call(this, WebInspector.UIString("Metrics"));
  787.  
  788. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
  789. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
  790. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._attributesUpdated, this);
  791. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._attributesUpdated, this);
  792. }
  793.  
  794. WebInspector.MetricsSidebarPane.prototype = {
  795.  
  796. update: function(node)
  797. {
  798. if (node)
  799. this.node = node;
  800. this._innerUpdate();
  801. },
  802.  
  803. _innerUpdate: function()
  804. {
  805.  
  806.  
  807. if (this._isEditingMetrics)
  808. return;
  809.  
  810.  
  811. var node = this.node;
  812.  
  813. if (!node || node.nodeType() !== Node.ELEMENT_NODE) {
  814. this.bodyElement.removeChildren();
  815. return;
  816. }
  817.  
  818. function callback(style)
  819. {
  820. if (!style || this.node !== node)
  821. return;
  822. this._updateMetrics(style);
  823. }
  824. WebInspector.cssModel.getComputedStyleAsync(node.id, callback.bind(this));
  825.  
  826. function inlineStyleCallback(style)
  827. {
  828. if (!style || this.node !== node)
  829. return;
  830. this.inlineStyle = style;
  831. }
  832. WebInspector.cssModel.getInlineStylesAsync(node.id, inlineStyleCallback.bind(this));
  833. },
  834.  
  835. _styleSheetOrMediaQueryResultChanged: function()
  836. {
  837. this._innerUpdate();
  838. },
  839.  
  840. _attributesUpdated: function(event)
  841. {
  842. if (this.node !== event.data.node)
  843. return;
  844.  
  845. this._innerUpdate();
  846. },
  847.  
  848. _getPropertyValueAsPx: function(style, propertyName)
  849. {
  850. return Number(style.getPropertyValue(propertyName).replace(/px$/, "") || 0);
  851. },
  852.  
  853. _getBox: function(computedStyle, componentName)
  854. {
  855. var suffix = componentName === "border" ? "-width" : "";
  856. var left = this._getPropertyValueAsPx(computedStyle, componentName + "-left" + suffix);
  857. var top = this._getPropertyValueAsPx(computedStyle, componentName + "-top" + suffix);
  858. var right = this._getPropertyValueAsPx(computedStyle, componentName + "-right" + suffix);
  859. var bottom = this._getPropertyValueAsPx(computedStyle, componentName + "-bottom" + suffix);
  860. return { left: left, top: top, right: right, bottom: bottom };
  861. },
  862.  
  863. _highlightDOMNode: function(showHighlight, mode, event)
  864. {
  865. event.consume();
  866. var nodeId = showHighlight && this.node ? this.node.id : 0;
  867. if (nodeId) {
  868. if (this._highlightMode === mode)
  869. return;
  870. this._highlightMode = mode;
  871. WebInspector.domAgent.highlightDOMNode(nodeId, mode);
  872. } else {
  873. delete this._highlightMode;
  874. WebInspector.domAgent.hideDOMNodeHighlight();
  875. }
  876.  
  877. for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) {
  878. var element = this._boxElements[i];
  879. if (!nodeId || mode === "all" || element._name === mode)
  880. element.style.backgroundColor = element._backgroundColor;
  881. else
  882. element.style.backgroundColor = "";
  883. }
  884. },
  885.  
  886. _updateMetrics: function(style)
  887. {
  888.  
  889. var metricsElement = document.createElement("div");
  890. metricsElement.className = "metrics";
  891. var self = this;
  892.  
  893. function createBoxPartElement(style, name, side, suffix)
  894. {
  895. var propertyName = (name !== "position" ? name + "-" : "") + side + suffix;
  896. var value = style.getPropertyValue(propertyName);
  897. if (value === "" || (name !== "position" && value === "0px"))
  898. value = "\u2012";
  899. else if (name === "position" && value === "auto")
  900. value = "\u2012";
  901. value = value.replace(/px$/, "");
  902.  
  903. var element = document.createElement("div");
  904. element.className = side;
  905. element.textContent = value;
  906. element.addEventListener("dblclick", this.startEditing.bind(this, element, name, propertyName, style), false);
  907. return element;
  908. }
  909.  
  910. function getContentAreaWidthPx(style)
  911. {
  912. var width = style.getPropertyValue("width").replace(/px$/, "");
  913. if (style.getPropertyValue("box-sizing") === "border-box") {
  914. var borderBox = self._getBox(style, "border");
  915. var paddingBox = self._getBox(style, "padding");
  916.  
  917. width = width - borderBox.left - borderBox.right - paddingBox.left - paddingBox.right;
  918. }
  919.  
  920. return width;
  921. }
  922.  
  923. function getContentAreaHeightPx(style)
  924. {
  925. var height = style.getPropertyValue("height").replace(/px$/, "");
  926. if (style.getPropertyValue("box-sizing") === "border-box") {
  927. var borderBox = self._getBox(style, "border");
  928. var paddingBox = self._getBox(style, "padding");
  929.  
  930. height = height - borderBox.top - borderBox.bottom - paddingBox.top - paddingBox.bottom;
  931. }
  932.  
  933. return height;
  934. }
  935.  
  936.  
  937. var noMarginDisplayType = {
  938. "table-cell": true,
  939. "table-column": true,
  940. "table-column-group": true,
  941. "table-footer-group": true,
  942. "table-header-group": true,
  943. "table-row": true,
  944. "table-row-group": true
  945. };
  946.  
  947.  
  948. var noPaddingDisplayType = {
  949. "table-column": true,
  950. "table-column-group": true,
  951. "table-footer-group": true,
  952. "table-header-group": true,
  953. "table-row": true,
  954. "table-row-group": true
  955. };
  956.  
  957.  
  958. var noPositionType = {
  959. "static": true
  960. };
  961.  
  962. var boxes = ["content", "padding", "border", "margin", "position"];
  963. var boxColors = [
  964. WebInspector.Color.PageHighlight.Content,
  965. WebInspector.Color.PageHighlight.Padding,
  966. WebInspector.Color.PageHighlight.Border,
  967. WebInspector.Color.PageHighlight.Margin,
  968. WebInspector.Color.fromRGBA(0, 0, 0, 0)
  969. ];
  970. var boxLabels = [WebInspector.UIString("content"), WebInspector.UIString("padding"), WebInspector.UIString("border"), WebInspector.UIString("margin"), WebInspector.UIString("position")];
  971. var previousBox = null;
  972. this._boxElements = [];
  973. for (var i = 0; i < boxes.length; ++i) {
  974. var name = boxes[i];
  975.  
  976. if (name === "margin" && noMarginDisplayType[style.getPropertyValue("display")])
  977. continue;
  978. if (name === "padding" && noPaddingDisplayType[style.getPropertyValue("display")])
  979. continue;
  980. if (name === "position" && noPositionType[style.getPropertyValue("position")])
  981. continue;
  982.  
  983. var boxElement = document.createElement("div");
  984. boxElement.className = name;
  985. boxElement._backgroundColor = boxColors[i].toString("original");
  986. boxElement._name = name;
  987. boxElement.style.backgroundColor = boxElement._backgroundColor;
  988. boxElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, true, name === "position" ? "all" : name), false);
  989. this._boxElements.push(boxElement);
  990.  
  991. if (name === "content") {
  992. var widthElement = document.createElement("span");
  993. widthElement.textContent = getContentAreaWidthPx(style);
  994. widthElement.addEventListener("dblclick", this.startEditing.bind(this, widthElement, "width", "width", style), false);
  995.  
  996. var heightElement = document.createElement("span");
  997. heightElement.textContent = getContentAreaHeightPx(style);
  998. heightElement.addEventListener("dblclick", this.startEditing.bind(this, heightElement, "height", "height", style), false);
  999.  
  1000. boxElement.appendChild(widthElement);
  1001. boxElement.appendChild(document.createTextNode(" \u00D7 "));
  1002. boxElement.appendChild(heightElement);
  1003. } else {
  1004. var suffix = (name === "border" ? "-width" : "");
  1005.  
  1006. var labelElement = document.createElement("div");
  1007. labelElement.className = "label";
  1008. labelElement.textContent = boxLabels[i];
  1009. boxElement.appendChild(labelElement);
  1010.  
  1011. boxElement.appendChild(createBoxPartElement.call(this, style, name, "top", suffix));
  1012. boxElement.appendChild(document.createElement("br"));
  1013. boxElement.appendChild(createBoxPartElement.call(this, style, name, "left", suffix));
  1014.  
  1015. if (previousBox)
  1016. boxElement.appendChild(previousBox);
  1017.  
  1018. boxElement.appendChild(createBoxPartElement.call(this, style, name, "right", suffix));
  1019. boxElement.appendChild(document.createElement("br"));
  1020. boxElement.appendChild(createBoxPartElement.call(this, style, name, "bottom", suffix));
  1021. }
  1022.  
  1023. previousBox = boxElement;
  1024. }
  1025.  
  1026. metricsElement.appendChild(previousBox);
  1027. metricsElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, false, ""), false);
  1028. this.bodyElement.removeChildren();
  1029. this.bodyElement.appendChild(metricsElement);
  1030. },
  1031.  
  1032. startEditing: function(targetElement, box, styleProperty, computedStyle)
  1033. {
  1034. if (WebInspector.isBeingEdited(targetElement))
  1035. return;
  1036.  
  1037. var context = { box: box, styleProperty: styleProperty, computedStyle: computedStyle };
  1038. var boundKeyDown = this._handleKeyDown.bind(this, context, styleProperty);
  1039. context.keyDownHandler = boundKeyDown;
  1040. targetElement.addEventListener("keydown", boundKeyDown, false);
  1041.  
  1042. this._isEditingMetrics = true;
  1043.  
  1044. var config = new WebInspector.EditingConfig(this.editingCommitted.bind(this), this.editingCancelled.bind(this), context);
  1045. WebInspector.startEditing(targetElement, config);
  1046.  
  1047. window.getSelection().setBaseAndExtent(targetElement, 0, targetElement, 1);
  1048. },
  1049.  
  1050. _handleKeyDown: function(context, styleProperty, event)
  1051. {
  1052. var element = event.currentTarget;
  1053.  
  1054. function finishHandler(originalValue, replacementString)
  1055. {
  1056. this._applyUserInput(element, replacementString, originalValue, context, false);
  1057. }
  1058.  
  1059. function customNumberHandler(number)
  1060. {
  1061. if (styleProperty !== "margin" && number < 0)
  1062. number = 0;
  1063. return number;
  1064. }
  1065.  
  1066. WebInspector.handleElementValueModifications(event, element, finishHandler.bind(this), undefined, customNumberHandler);
  1067. },
  1068.  
  1069. editingEnded: function(element, context)
  1070. {
  1071. delete this.originalPropertyData;
  1072. delete this.previousPropertyDataCandidate;
  1073. element.removeEventListener("keydown", context.keyDownHandler, false);
  1074. delete this._isEditingMetrics;
  1075. },
  1076.  
  1077. editingCancelled: function(element, context)
  1078. {
  1079. if ("originalPropertyData" in this && this.inlineStyle) {
  1080. if (!this.originalPropertyData) {
  1081.  
  1082. var pastLastSourcePropertyIndex = this.inlineStyle.pastLastSourcePropertyIndex();
  1083. if (pastLastSourcePropertyIndex)
  1084. this.inlineStyle.allProperties[pastLastSourcePropertyIndex - 1].setText("", false);
  1085. } else
  1086. this.inlineStyle.allProperties[this.originalPropertyData.index].setText(this.originalPropertyData.propertyText, false);
  1087. }
  1088. this.editingEnded(element, context);
  1089. this.update();
  1090. },
  1091.  
  1092. _applyUserInput: function(element, userInput, previousContent, context, commitEditor)
  1093. {
  1094. if (!this.inlineStyle) {
  1095.  
  1096. return this.editingCancelled(element, context); 
  1097. }
  1098.  
  1099. if (commitEditor && userInput === previousContent)
  1100. return this.editingCancelled(element, context); 
  1101.  
  1102. if (context.box !== "position" && (!userInput || userInput === "\u2012"))
  1103. userInput = "0px";
  1104. else if (context.box === "position" && (!userInput || userInput === "\u2012"))
  1105. userInput = "auto";
  1106.  
  1107. userInput = userInput.toLowerCase();
  1108.  
  1109. if (/^\d+$/.test(userInput))
  1110. userInput += "px";
  1111.  
  1112. var styleProperty = context.styleProperty;
  1113. var computedStyle = context.computedStyle;
  1114.  
  1115. if (computedStyle.getPropertyValue("box-sizing") === "border-box" && (styleProperty === "width" || styleProperty === "height")) {
  1116. if (!userInput.match(/px$/)) {
  1117. WebInspector.log("For elements with box-sizing: border-box, only absolute content area dimensions can be applied", WebInspector.ConsoleMessage.MessageLevel.Error, true);
  1118. return;
  1119. }
  1120.  
  1121. var borderBox = this._getBox(computedStyle, "border");
  1122. var paddingBox = this._getBox(computedStyle, "padding");
  1123. var userValuePx = Number(userInput.replace(/px$/, ""));
  1124. if (isNaN(userValuePx))
  1125. return;
  1126. if (styleProperty === "width")
  1127. userValuePx += borderBox.left + borderBox.right + paddingBox.left + paddingBox.right;
  1128. else
  1129. userValuePx += borderBox.top + borderBox.bottom + paddingBox.top + paddingBox.bottom;
  1130.  
  1131. userInput = userValuePx + "px";
  1132. }
  1133.  
  1134. this.previousPropertyDataCandidate = null;
  1135. var self = this;
  1136. var callback = function(style) {
  1137. if (!style)
  1138. return;
  1139. self.inlineStyle = style;
  1140. if (!("originalPropertyData" in self))
  1141. self.originalPropertyData = self.previousPropertyDataCandidate;
  1142.  
  1143. if (typeof self._highlightMode !== "undefined") {
  1144. WebInspector.domAgent.highlightDOMNode(self.node.id, self._highlightMode);
  1145. }
  1146.  
  1147. if (commitEditor) {
  1148. self.dispatchEventToListeners("metrics edited");
  1149. self.update();
  1150. }
  1151. };
  1152.  
  1153. var allProperties = this.inlineStyle.allProperties;
  1154. for (var i = 0; i < allProperties.length; ++i) {
  1155. var property = allProperties[i];
  1156. if (property.name !== context.styleProperty || property.inactive)
  1157. continue;
  1158.  
  1159. this.previousPropertyDataCandidate = property;
  1160. property.setValue(userInput, commitEditor, true, callback);
  1161. return;
  1162. }
  1163.  
  1164. this.inlineStyle.appendProperty(context.styleProperty, userInput, callback);
  1165. },
  1166.  
  1167. editingCommitted: function(element, userInput, previousContent, context)
  1168. {
  1169. this.editingEnded(element, context);
  1170. this._applyUserInput(element, userInput, previousContent, context, true);
  1171. },
  1172.  
  1173. __proto__: WebInspector.SidebarPane.prototype
  1174. }
  1175. ;
  1176.  
  1177.  
  1178.  
  1179. WebInspector.PropertiesSidebarPane = function()
  1180. {
  1181. WebInspector.SidebarPane.call(this, WebInspector.UIString("Properties"));
  1182. }
  1183.  
  1184. WebInspector.PropertiesSidebarPane._objectGroupName = "properties-sidebar-pane";
  1185.  
  1186. WebInspector.PropertiesSidebarPane.prototype = {
  1187. update: function(node)
  1188. {
  1189. var body = this.bodyElement;
  1190.  
  1191. if (!node) {
  1192. body.removeChildren();
  1193. this.sections = [];
  1194. return;
  1195. }
  1196.  
  1197. WebInspector.RemoteObject.resolveNode(node, WebInspector.PropertiesSidebarPane._objectGroupName, nodeResolved.bind(this));
  1198.  
  1199. function nodeResolved(object)
  1200. {
  1201. if (!object)
  1202. return;
  1203. function protoList()
  1204. {
  1205. var proto = this;
  1206. var result = {};
  1207. var counter = 1;
  1208. while (proto) {
  1209. result[counter++] = proto;
  1210. proto = proto.__proto__;
  1211. }
  1212. return result;
  1213. }
  1214. object.callFunction(protoList, undefined, nodePrototypesReady.bind(this));
  1215. object.release();
  1216. }
  1217.  
  1218. function nodePrototypesReady(object)
  1219. {
  1220. if (!object)
  1221. return;
  1222. object.getOwnProperties(fillSection.bind(this));
  1223. }
  1224.  
  1225. function fillSection(prototypes)
  1226. {
  1227. if (!prototypes)
  1228. return;
  1229.  
  1230. var body = this.bodyElement;
  1231. body.removeChildren();
  1232. this.sections = [];
  1233.  
  1234.  
  1235. for (var i = 0; i < prototypes.length; ++i) {
  1236. if (!parseInt(prototypes[i].name, 10))
  1237. continue;
  1238.  
  1239. var prototype = prototypes[i].value;
  1240. var title = prototype.description;
  1241. if (title.match(/Prototype$/))
  1242. title = title.replace(/Prototype$/, "");
  1243. var section = new WebInspector.ObjectPropertiesSection(prototype, title);
  1244. this.sections.push(section);
  1245. body.appendChild(section.element);
  1246. }
  1247. }
  1248. },
  1249.  
  1250. __proto__: WebInspector.SidebarPane.prototype
  1251. }
  1252. ;
  1253.  
  1254.  
  1255.  
  1256. WebInspector.StylesSidebarPane = function(computedStylePane, setPseudoClassCallback)
  1257. {
  1258. WebInspector.SidebarPane.call(this, WebInspector.UIString("Styles"));
  1259.  
  1260. this.settingsSelectElement = document.createElement("select");
  1261. this.settingsSelectElement.className = "select-settings";
  1262.  
  1263. var option = document.createElement("option");
  1264. option.value = WebInspector.Color.Format.Original;
  1265. option.label = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "As authored" : "As Authored");
  1266. this.settingsSelectElement.appendChild(option);
  1267.  
  1268. option = document.createElement("option");
  1269. option.value = WebInspector.Color.Format.HEX;
  1270. option.label = WebInspector.UIString("Hex Colors");
  1271. this.settingsSelectElement.appendChild(option);
  1272.  
  1273. option = document.createElement("option");
  1274. option.value = WebInspector.Color.Format.RGB;
  1275. option.label = WebInspector.UIString("RGB Colors");
  1276. this.settingsSelectElement.appendChild(option);
  1277.  
  1278. option = document.createElement("option");
  1279. option.value = WebInspector.Color.Format.HSL;
  1280. option.label = WebInspector.UIString("HSL Colors");
  1281. this.settingsSelectElement.appendChild(option);
  1282.  
  1283.  
  1284. var muteEventListener = function(event) { event.consume(true); };
  1285.  
  1286. this.settingsSelectElement.addEventListener("click", muteEventListener, true);
  1287. this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
  1288. this._updateColorFormatFilter();
  1289.  
  1290. this.titleElement.appendChild(this.settingsSelectElement);
  1291.  
  1292. this._elementStateButton = document.createElement("button");
  1293. this._elementStateButton.className = "pane-title-button element-state";
  1294. this._elementStateButton.title = WebInspector.UIString("Toggle Element State");
  1295. this._elementStateButton.addEventListener("click", this._toggleElementStatePane.bind(this), false);
  1296. this.titleElement.appendChild(this._elementStateButton);
  1297.  
  1298. var addButton = document.createElement("button");
  1299. addButton.className = "pane-title-button add";
  1300. addButton.id = "add-style-button-test-id";
  1301. addButton.title = WebInspector.UIString("New Style Rule");
  1302. addButton.addEventListener("click", this._createNewRule.bind(this), false);
  1303. this.titleElement.appendChild(addButton);
  1304.  
  1305. this._computedStylePane = computedStylePane;
  1306. computedStylePane._stylesSidebarPane = this;
  1307. this._setPseudoClassCallback = setPseudoClassCallback;
  1308. this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
  1309. WebInspector.settings.colorFormat.addChangeListener(this._colorFormatSettingChanged.bind(this));
  1310.  
  1311. this._createElementStatePane();
  1312. this.bodyElement.appendChild(this._elementStatePane);
  1313. this._sectionsContainer = document.createElement("div");
  1314. this.bodyElement.appendChild(this._sectionsContainer);
  1315.  
  1316. this._spectrumHelper = new WebInspector.SpectrumPopupHelper();
  1317. this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.DefaultCSSFormatter());
  1318.  
  1319. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
  1320. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
  1321. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._attributeChanged, this);
  1322. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._attributeChanged, this);
  1323. WebInspector.settings.showUserAgentStyles.addChangeListener(this._showUserAgentStylesSettingChanged.bind(this));
  1324. }
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330. WebInspector.StylesSidebarPane.PseudoIdNames = [
  1331. "", "first-line", "first-letter", "before", "after", "selection", "", "-webkit-scrollbar", "-webkit-file-upload-button",
  1332. "-webkit-input-placeholder", "-webkit-slider-thumb", "-webkit-search-cancel-button", "-webkit-search-decoration",
  1333. "-webkit-search-results-decoration", "-webkit-search-results-button", "-webkit-media-controls-panel",
  1334. "-webkit-media-controls-play-button", "-webkit-media-controls-mute-button", "-webkit-media-controls-timeline",
  1335. "-webkit-media-controls-timeline-container", "-webkit-media-controls-volume-slider",
  1336. "-webkit-media-controls-volume-slider-container", "-webkit-media-controls-current-time-display",
  1337. "-webkit-media-controls-time-remaining-display", "-webkit-media-controls-seek-back-button", "-webkit-media-controls-seek-forward-button",
  1338. "-webkit-media-controls-fullscreen-button", "-webkit-media-controls-rewind-button", "-webkit-media-controls-return-to-realtime-button",
  1339. "-webkit-media-controls-toggle-closed-captions-button", "-webkit-media-controls-status-display", "-webkit-scrollbar-thumb",
  1340. "-webkit-scrollbar-button", "-webkit-scrollbar-track", "-webkit-scrollbar-track-piece", "-webkit-scrollbar-corner",
  1341. "-webkit-resizer", "-webkit-inner-spin-button", "-webkit-outer-spin-button"
  1342. ];
  1343.  
  1344. WebInspector.StylesSidebarPane.canonicalPropertyName = function(name)
  1345. {
  1346. if (!name || name.length < 9 || name.charAt(0) !== "-")
  1347. return name;
  1348. var match = name.match(/(?:-webkit-|-khtml-|-apple-)(.+)/);
  1349. if (!match)
  1350. return name;
  1351. return match[1];
  1352. }
  1353.  
  1354. WebInspector.StylesSidebarPane.createExclamationMark = function(propertyName)
  1355. {
  1356. var exclamationElement = document.createElement("img");
  1357. exclamationElement.className = "exclamation-mark";
  1358. exclamationElement.title = WebInspector.CSSCompletions.cssPropertiesMetainfo.keySet()[propertyName.toLowerCase()] ? WebInspector.UIString("Invalid property value.") : WebInspector.UIString("Unknown property name.");
  1359. return exclamationElement;
  1360. }
  1361.  
  1362. WebInspector.StylesSidebarPane.prototype = {
  1363. _contextMenuEventFired: function(event)
  1364. {
  1365.  
  1366.  
  1367. var contextMenu = new WebInspector.ContextMenu(event);
  1368. contextMenu.appendApplicableItems(event.target);
  1369. contextMenu.show();
  1370. },
  1371.  
  1372. get _forcedPseudoClasses()
  1373. {
  1374. return this.node ? (this.node.getUserProperty("pseudoState") || undefined) : undefined;
  1375. },
  1376.  
  1377. _updateForcedPseudoStateInputs: function()
  1378. {
  1379. if (!this.node)
  1380. return;
  1381.  
  1382. var nodePseudoState = this._forcedPseudoClasses;
  1383. if (!nodePseudoState)
  1384. nodePseudoState = [];
  1385.  
  1386. var inputs = this._elementStatePane.inputs;
  1387. for (var i = 0; i < inputs.length; ++i)
  1388. inputs[i].checked = nodePseudoState.indexOf(inputs[i].state) >= 0;
  1389. },
  1390.  
  1391. update: function(node, forceUpdate)
  1392. {
  1393. this._spectrumHelper.hide();
  1394.  
  1395. var refresh = false;
  1396.  
  1397. if (forceUpdate)
  1398. delete this.node;
  1399.  
  1400. if (!forceUpdate && (node === this.node))
  1401. refresh = true;
  1402.  
  1403. if (node && node.nodeType() === Node.TEXT_NODE && node.parentNode)
  1404. node = node.parentNode;
  1405.  
  1406. if (node && node.nodeType() !== Node.ELEMENT_NODE)
  1407. node = null;
  1408.  
  1409. if (node)
  1410. this.node = node;
  1411. else
  1412. node = this.node;
  1413.  
  1414. this._updateForcedPseudoStateInputs();
  1415.  
  1416. if (refresh)
  1417. this._refreshUpdate();
  1418. else
  1419. this._rebuildUpdate();
  1420. },
  1421.  
  1422.  
  1423. _refreshUpdate: function(editedSection, forceFetchComputedStyle, userCallback)
  1424. {
  1425. if (this._refreshUpdateInProgress) {
  1426. this._lastNodeForInnerRefresh = this.node;
  1427. return;
  1428. }
  1429.  
  1430. var node = this._validateNode(userCallback);
  1431. if (!node)
  1432. return;
  1433.  
  1434. function computedStyleCallback(computedStyle)
  1435. {
  1436. delete this._refreshUpdateInProgress;
  1437.  
  1438. if (this._lastNodeForInnerRefresh) {
  1439. delete this._lastNodeForInnerRefresh;
  1440. this._refreshUpdate(editedSection, forceFetchComputedStyle, userCallback);
  1441. return;
  1442. }
  1443.  
  1444. if (this.node === node && computedStyle)
  1445. this._innerRefreshUpdate(node, computedStyle, editedSection);
  1446.  
  1447. if (userCallback)
  1448. userCallback();
  1449. }
  1450.  
  1451. if (this._computedStylePane.expanded || forceFetchComputedStyle) {
  1452. this._refreshUpdateInProgress = true;
  1453. WebInspector.cssModel.getComputedStyleAsync(node.id, computedStyleCallback.bind(this));
  1454. } else {
  1455. this._innerRefreshUpdate(node, null, editedSection);
  1456. if (userCallback)
  1457. userCallback();
  1458. }
  1459. },
  1460.  
  1461. _rebuildUpdate: function()
  1462. {
  1463. if (this._rebuildUpdateInProgress) {
  1464. this._lastNodeForInnerRebuild = this.node;
  1465. return;
  1466. }
  1467.  
  1468. var node = this._validateNode();
  1469. if (!node)
  1470. return;
  1471.  
  1472. this._rebuildUpdateInProgress = true;
  1473.  
  1474. var resultStyles = {};
  1475.  
  1476. function stylesCallback(matchedResult)
  1477. {
  1478. delete this._rebuildUpdateInProgress;
  1479.  
  1480. var lastNodeForRebuild = this._lastNodeForInnerRebuild;
  1481. if (lastNodeForRebuild) {
  1482. delete this._lastNodeForInnerRebuild;
  1483. if (lastNodeForRebuild !== this.node) {
  1484. this._rebuildUpdate();
  1485. return;
  1486. }
  1487. }
  1488.  
  1489. if (matchedResult && this.node === node) {
  1490. resultStyles.matchedCSSRules = matchedResult.matchedCSSRules;
  1491. resultStyles.pseudoElements = matchedResult.pseudoElements;
  1492. resultStyles.inherited = matchedResult.inherited;
  1493. this._innerRebuildUpdate(node, resultStyles);
  1494. }
  1495.  
  1496. if (lastNodeForRebuild) {
  1497.  
  1498. this._rebuildUpdate();
  1499. return;
  1500. }
  1501. }
  1502.  
  1503. function inlineCallback(inlineStyle, attributesStyle)
  1504. {
  1505. resultStyles.inlineStyle = inlineStyle;
  1506. resultStyles.attributesStyle = attributesStyle;
  1507. }
  1508.  
  1509. function computedCallback(computedStyle)
  1510. {
  1511. resultStyles.computedStyle = computedStyle;
  1512. }
  1513.  
  1514. if (this._computedStylePane.expanded)
  1515. WebInspector.cssModel.getComputedStyleAsync(node.id, computedCallback.bind(this));
  1516. WebInspector.cssModel.getInlineStylesAsync(node.id, inlineCallback.bind(this));
  1517. WebInspector.cssModel.getMatchedStylesAsync(node.id, true, true, stylesCallback.bind(this));
  1518. },
  1519.  
  1520.  
  1521. _validateNode: function(userCallback)
  1522. {
  1523. if (!this.node) {
  1524. this._sectionsContainer.removeChildren();
  1525. this._computedStylePane.bodyElement.removeChildren();
  1526. this.sections = {};
  1527. if (userCallback)
  1528. userCallback();
  1529. return null;
  1530. }
  1531. return this.node;
  1532. },
  1533.  
  1534. _styleSheetOrMediaQueryResultChanged: function()
  1535. {
  1536. if (this._userOperation || this._isEditingStyle)
  1537. return;
  1538.  
  1539. this._rebuildUpdate();
  1540. },
  1541.  
  1542. _attributeChanged: function(event)
  1543. {
  1544.  
  1545.  
  1546. if (this._isEditingStyle || this._userOperation)
  1547. return;
  1548.  
  1549. if (!this._canAffectCurrentStyles(event.data.node))
  1550. return;
  1551.  
  1552. this._rebuildUpdate();
  1553. },
  1554.  
  1555. _canAffectCurrentStyles: function(node)
  1556. {
  1557. return this.node && (this.node === node || node.parentNode === this.node.parentNode || node.isAncestor(this.node));
  1558. },
  1559.  
  1560. _innerRefreshUpdate: function(node, computedStyle, editedSection)
  1561. {
  1562. for (var pseudoId in this.sections) {
  1563. var styleRules = this._refreshStyleRules(this.sections[pseudoId], computedStyle);
  1564. var usedProperties = {};
  1565. this._markUsedProperties(styleRules, usedProperties);
  1566. this._refreshSectionsForStyleRules(styleRules, usedProperties, editedSection);
  1567. }
  1568. if (computedStyle)
  1569. this.sections[0][0].rebuildComputedTrace(this.sections[0]);
  1570.  
  1571. this._nodeStylesUpdatedForTest(node, false);
  1572. },
  1573.  
  1574. _innerRebuildUpdate: function(node, styles)
  1575. {
  1576. this._sectionsContainer.removeChildren();
  1577. this._computedStylePane.bodyElement.removeChildren();
  1578. this._linkifier.reset();
  1579.  
  1580. var styleRules = this._rebuildStyleRules(node, styles);
  1581. var usedProperties = {};
  1582. this._markUsedProperties(styleRules, usedProperties);
  1583. this.sections[0] = this._rebuildSectionsForStyleRules(styleRules, usedProperties, 0, null);
  1584. var anchorElement = this.sections[0].inheritedPropertiesSeparatorElement;
  1585.  
  1586. if (styles.computedStyle)        
  1587. this.sections[0][0].rebuildComputedTrace(this.sections[0]);
  1588.  
  1589. for (var i = 0; i < styles.pseudoElements.length; ++i) {
  1590. var pseudoElementCSSRules = styles.pseudoElements[i];
  1591.  
  1592. styleRules = [];
  1593. var pseudoId = pseudoElementCSSRules.pseudoId;
  1594.  
  1595. var entry = { isStyleSeparator: true, pseudoId: pseudoId };
  1596. styleRules.push(entry);
  1597.  
  1598.  
  1599. for (var j = pseudoElementCSSRules.rules.length - 1; j >= 0; --j) {
  1600. var rule = pseudoElementCSSRules.rules[j];
  1601. styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) });
  1602. }
  1603. usedProperties = {};
  1604. this._markUsedProperties(styleRules, usedProperties);
  1605. this.sections[pseudoId] = this._rebuildSectionsForStyleRules(styleRules, usedProperties, pseudoId, anchorElement);
  1606. }
  1607.  
  1608. this._nodeStylesUpdatedForTest(node, true);
  1609. },
  1610.  
  1611. _nodeStylesUpdatedForTest: function(node, rebuild)
  1612. {
  1613.  
  1614. },
  1615.  
  1616. _refreshStyleRules: function(sections, computedStyle)
  1617. {
  1618. var nodeComputedStyle = computedStyle;
  1619. var styleRules = [];
  1620. for (var i = 0; sections && i < sections.length; ++i) {
  1621. var section = sections[i];
  1622. if (section.isBlank)
  1623. continue;
  1624. if (section.computedStyle)
  1625. section.styleRule.style = nodeComputedStyle;
  1626. var styleRule = { section: section, style: section.styleRule.style, computedStyle: section.computedStyle, rule: section.rule, editable: !!(section.styleRule.style && section.styleRule.style.id), isAttribute: section.styleRule.isAttribute, isInherited: section.styleRule.isInherited };
  1627. styleRules.push(styleRule);
  1628. }
  1629. return styleRules;
  1630. },
  1631.  
  1632. _rebuildStyleRules: function(node, styles)
  1633. {
  1634. var nodeComputedStyle = styles.computedStyle;
  1635. this.sections = {};
  1636.  
  1637. var styleRules = [];
  1638.  
  1639. function addAttributesStyle()
  1640. {
  1641. if (!styles.attributesStyle)
  1642. return;
  1643. var attrStyle = { style: styles.attributesStyle, editable: false };
  1644. attrStyle.selectorText = node.nodeNameInCorrectCase() + "[" + WebInspector.UIString("Attributes Style") + "]";
  1645. styleRules.push(attrStyle);
  1646. }
  1647.  
  1648. styleRules.push({ computedStyle: true, selectorText: "", style: nodeComputedStyle, editable: false });
  1649.  
  1650.  
  1651. if (styles.inlineStyle && node.nodeType() === Node.ELEMENT_NODE) {
  1652. var inlineStyle = { selectorText: "element.style", style: styles.inlineStyle, isAttribute: true };
  1653. styleRules.push(inlineStyle);
  1654. }
  1655.  
  1656.  
  1657. if (styles.matchedCSSRules.length)
  1658. styleRules.push({ isStyleSeparator: true, text: WebInspector.UIString("Matched CSS Rules") });
  1659. var addedAttributesStyle;
  1660. for (var i = styles.matchedCSSRules.length - 1; i >= 0; --i) {
  1661. var rule = styles.matchedCSSRules[i];
  1662. if (!WebInspector.settings.showUserAgentStyles.get() && (rule.isUser || rule.isUserAgent))
  1663. continue;
  1664. if ((rule.isUser || rule.isUserAgent) && !addedAttributesStyle) {
  1665.  
  1666. addedAttributesStyle = true;
  1667. addAttributesStyle();
  1668. }
  1669. styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) });
  1670. }
  1671.  
  1672. if (!addedAttributesStyle)
  1673. addAttributesStyle();
  1674.  
  1675.  
  1676. var parentNode = node.parentNode;
  1677. function insertInheritedNodeSeparator(node)
  1678. {
  1679. var entry = {};
  1680. entry.isStyleSeparator = true;
  1681. entry.node = node;
  1682. styleRules.push(entry);
  1683. }
  1684.  
  1685. for (var parentOrdinal = 0; parentOrdinal < styles.inherited.length; ++parentOrdinal) {
  1686. var parentStyles = styles.inherited[parentOrdinal];
  1687. var separatorInserted = false;
  1688. if (parentStyles.inlineStyle) {
  1689. if (this._containsInherited(parentStyles.inlineStyle)) {
  1690. var inlineStyle = { selectorText: WebInspector.UIString("Style Attribute"), style: parentStyles.inlineStyle, isAttribute: true, isInherited: true, parentNode: parentNode };
  1691. if (!separatorInserted) {
  1692. insertInheritedNodeSeparator(parentNode);
  1693. separatorInserted = true;
  1694. }
  1695. styleRules.push(inlineStyle);
  1696. }
  1697. }
  1698.  
  1699. for (var i = parentStyles.matchedCSSRules.length - 1; i >= 0; --i) {
  1700. var rulePayload = parentStyles.matchedCSSRules[i];
  1701. if (!this._containsInherited(rulePayload.style))
  1702. continue;
  1703. var rule = rulePayload;
  1704. if (!WebInspector.settings.showUserAgentStyles.get() && (rule.isUser || rule.isUserAgent))
  1705. continue;
  1706.  
  1707. if (!separatorInserted) {
  1708. insertInheritedNodeSeparator(parentNode);
  1709. separatorInserted = true;
  1710. }
  1711. styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, isInherited: true, parentNode: parentNode, editable: !!(rule.style && rule.style.id) });
  1712. }
  1713. parentNode = parentNode.parentNode;
  1714. }
  1715. return styleRules;
  1716. },
  1717.  
  1718. _markUsedProperties: function(styleRules, usedProperties)
  1719. {
  1720. var foundImportantProperties = {};
  1721. var propertyToEffectiveRule = {};
  1722. for (var i = 0; i < styleRules.length; ++i) {
  1723. var styleRule = styleRules[i];
  1724. if (styleRule.computedStyle || styleRule.isStyleSeparator)
  1725. continue;
  1726. if (styleRule.section && styleRule.section.noAffect)
  1727. continue;
  1728.  
  1729. styleRule.usedProperties = {};
  1730.  
  1731. var style = styleRule.style;
  1732. var allProperties = style.allProperties;
  1733. for (var j = 0; j < allProperties.length; ++j) {
  1734. var property = allProperties[j];
  1735. if (!property.isLive || !property.parsedOk)
  1736. continue;
  1737.  
  1738. var canonicalName = WebInspector.StylesSidebarPane.canonicalPropertyName(property.name);
  1739.  
  1740. if (styleRule.isInherited && !WebInspector.CSSKeywordCompletions.InheritedProperties[canonicalName])
  1741. continue;
  1742.  
  1743. if (foundImportantProperties.hasOwnProperty(canonicalName))
  1744. continue;
  1745.  
  1746. var isImportant = property.priority.length;
  1747. if (!isImportant && usedProperties.hasOwnProperty(canonicalName))
  1748. continue;
  1749.  
  1750. if (isImportant) {
  1751. foundImportantProperties[canonicalName] = true;
  1752. if (propertyToEffectiveRule.hasOwnProperty(canonicalName))
  1753. delete propertyToEffectiveRule[canonicalName].usedProperties[canonicalName];
  1754. }
  1755.  
  1756. styleRule.usedProperties[canonicalName] = true;
  1757. usedProperties[canonicalName] = true;
  1758. propertyToEffectiveRule[canonicalName] = styleRule;
  1759. }
  1760. }
  1761. },
  1762.  
  1763. _refreshSectionsForStyleRules: function(styleRules, usedProperties, editedSection)
  1764. {
  1765.  
  1766. for (var i = 0; i < styleRules.length; ++i) {
  1767. var styleRule = styleRules[i];
  1768. var section = styleRule.section;
  1769. if (styleRule.computedStyle) {
  1770. section._usedProperties = usedProperties;
  1771. section.update();
  1772. } else {
  1773. section._usedProperties = styleRule.usedProperties;
  1774. section.update(section === editedSection);
  1775. }
  1776. }
  1777. },
  1778.  
  1779. _rebuildSectionsForStyleRules: function(styleRules, usedProperties, pseudoId, anchorElement)
  1780. {
  1781.  
  1782. var sections = [];
  1783. var lastWasSeparator = true;
  1784. for (var i = 0; i < styleRules.length; ++i) {
  1785. var styleRule = styleRules[i];
  1786. if (styleRule.isStyleSeparator) {
  1787. var separatorElement = document.createElement("div");
  1788. separatorElement.className = "sidebar-separator";
  1789. if (styleRule.node) {
  1790. var link = WebInspector.DOMPresentationUtils.linkifyNodeReference(styleRule.node);
  1791. separatorElement.appendChild(document.createTextNode(WebInspector.UIString("Inherited from") + " "));
  1792. separatorElement.appendChild(link);
  1793. if (!sections.inheritedPropertiesSeparatorElement)
  1794. sections.inheritedPropertiesSeparatorElement = separatorElement;
  1795. } else if ("pseudoId" in styleRule) {
  1796. var pseudoName = WebInspector.StylesSidebarPane.PseudoIdNames[styleRule.pseudoId];
  1797. if (pseudoName)
  1798. separatorElement.textContent = WebInspector.UIString("Pseudo ::%s element", pseudoName);
  1799. else
  1800. separatorElement.textContent = WebInspector.UIString("Pseudo element");
  1801. } else
  1802. separatorElement.textContent = styleRule.text;
  1803. this._sectionsContainer.insertBefore(separatorElement, anchorElement);
  1804. lastWasSeparator = true;
  1805. continue;
  1806. }
  1807. var computedStyle = styleRule.computedStyle;
  1808.  
  1809.  
  1810. var editable = styleRule.editable;
  1811. if (typeof editable === "undefined")
  1812. editable = true;
  1813.  
  1814. if (computedStyle)
  1815. var section = new WebInspector.ComputedStylePropertiesSection(this, styleRule, usedProperties);
  1816. else {
  1817. var section = new WebInspector.StylePropertiesSection(this, styleRule, editable, styleRule.isInherited, lastWasSeparator);
  1818. section._markSelectorMatches();
  1819. }
  1820. section.expanded = true;
  1821.  
  1822. if (computedStyle) {
  1823. this._computedStylePane.bodyElement.appendChild(section.element);
  1824. lastWasSeparator = true;
  1825. } else {
  1826. this._sectionsContainer.insertBefore(section.element, anchorElement);
  1827. lastWasSeparator = false;
  1828. }
  1829. sections.push(section);
  1830. }
  1831. return sections;
  1832. },
  1833.  
  1834. _containsInherited: function(style)
  1835. {
  1836. var properties = style.allProperties;
  1837. for (var i = 0; i < properties.length; ++i) {
  1838. var property = properties[i];
  1839.  
  1840. if (property.isLive && property.name in WebInspector.CSSKeywordCompletions.InheritedProperties)
  1841. return true;
  1842. }
  1843. return false;
  1844. },
  1845.  
  1846. _colorFormatSettingChanged: function(event)
  1847. {
  1848. this._updateColorFormatFilter();
  1849. for (var pseudoId in this.sections) {
  1850. var sections = this.sections[pseudoId];
  1851. for (var i = 0; i < sections.length; ++i)
  1852. sections[i].update(true);
  1853. }
  1854. },
  1855.  
  1856. _updateColorFormatFilter: function()
  1857. {
  1858.  
  1859. var selectedIndex = 0;
  1860. var value = WebInspector.settings.colorFormat.get();
  1861. var options = this.settingsSelectElement.options;
  1862. for (var i = 0; i < options.length; ++i) {
  1863. if (options[i].value === value) {
  1864. selectedIndex = i;
  1865. break;
  1866. }
  1867. }
  1868. this.settingsSelectElement.selectedIndex = selectedIndex;
  1869. },
  1870.  
  1871. _changeSetting: function(event)
  1872. {
  1873. var options = this.settingsSelectElement.options;
  1874. var selectedOption = options[this.settingsSelectElement.selectedIndex];
  1875. WebInspector.settings.colorFormat.set(selectedOption.value);
  1876. },
  1877.  
  1878. _createNewRule: function(event)
  1879. {
  1880. event.consume();
  1881. this.expanded = true;
  1882. this.addBlankSection().startEditingSelector();
  1883. },
  1884.  
  1885. addBlankSection: function()
  1886. {
  1887. var blankSection = new WebInspector.BlankStylePropertiesSection(this, this.node ? this.node.appropriateSelectorFor(true) : "");
  1888.  
  1889. var elementStyleSection = this.sections[0][1];
  1890. this._sectionsContainer.insertBefore(blankSection.element, elementStyleSection.element.nextSibling);
  1891.  
  1892. this.sections[0].splice(2, 0, blankSection);
  1893.  
  1894. return blankSection;
  1895. },
  1896.  
  1897. removeSection: function(section)
  1898. {
  1899. for (var pseudoId in this.sections) {
  1900. var sections = this.sections[pseudoId];
  1901. var index = sections.indexOf(section);
  1902. if (index === -1)
  1903. continue;
  1904. sections.splice(index, 1);
  1905. if (section.element.parentNode)
  1906. section.element.parentNode.removeChild(section.element);
  1907. }
  1908. },
  1909.  
  1910. registerShortcuts: function()
  1911. {
  1912. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Styles Pane"));
  1913. var shortcut = WebInspector.KeyboardShortcut;
  1914. var keys = [
  1915. shortcut.shortcutToString(shortcut.Keys.Tab),
  1916. shortcut.shortcutToString(shortcut.Keys.Tab, shortcut.Modifiers.Shift)
  1917. ];
  1918. section.addRelatedKeys(keys, WebInspector.UIString("Next/previous property"));
  1919. keys = [
  1920. shortcut.shortcutToString(shortcut.Keys.Up),
  1921. shortcut.shortcutToString(shortcut.Keys.Down)
  1922. ];
  1923. section.addRelatedKeys(keys, WebInspector.UIString("Increment/decrement value"));
  1924. keys = [
  1925. shortcut.shortcutToString(shortcut.Keys.Up, shortcut.Modifiers.Shift),
  1926. shortcut.shortcutToString(shortcut.Keys.Down, shortcut.Modifiers.Shift)
  1927. ];
  1928. section.addRelatedKeys(keys, WebInspector.UIString("Increment/decrement by %f", 10));
  1929. keys = [
  1930. shortcut.shortcutToString(shortcut.Keys.PageUp),
  1931. shortcut.shortcutToString(shortcut.Keys.PageDown)
  1932. ];
  1933. section.addRelatedKeys(keys, WebInspector.UIString("Increment/decrement by %f", 10));
  1934. keys = [
  1935. shortcut.shortcutToString(shortcut.Keys.PageUp, shortcut.Modifiers.Shift),
  1936. shortcut.shortcutToString(shortcut.Keys.PageDown, shortcut.Modifiers.Shift)
  1937. ];
  1938. section.addRelatedKeys(keys, WebInspector.UIString("Increment/decrement by %f", 100));
  1939. keys = [
  1940. shortcut.shortcutToString(shortcut.Keys.PageUp, shortcut.Modifiers.Alt),
  1941. shortcut.shortcutToString(shortcut.Keys.PageDown, shortcut.Modifiers.Alt)
  1942. ];
  1943. section.addRelatedKeys(keys, WebInspector.UIString("Increment/decrement by %f", 0.1));
  1944. },
  1945.  
  1946. _toggleElementStatePane: function(event)
  1947. {
  1948. event.consume();
  1949. if (!this._elementStateButton.hasStyleClass("toggled")) {
  1950. this.expand();
  1951. this._elementStateButton.addStyleClass("toggled");
  1952. this._elementStatePane.addStyleClass("expanded");
  1953. } else {
  1954. this._elementStateButton.removeStyleClass("toggled");
  1955. this._elementStatePane.removeStyleClass("expanded");
  1956. }
  1957. },
  1958.  
  1959. _createElementStatePane: function()
  1960. {
  1961. this._elementStatePane = document.createElement("div");
  1962. this._elementStatePane.className = "styles-element-state-pane source-code";
  1963. var table = document.createElement("table");
  1964.  
  1965. var inputs = [];
  1966. this._elementStatePane.inputs = inputs;
  1967.  
  1968. function clickListener(event)
  1969. {
  1970. var node = this._validateNode();
  1971. if (!node)
  1972. return;
  1973. this._setPseudoClassCallback(node.id, event.target.state, event.target.checked);
  1974. }
  1975.  
  1976. function createCheckbox(state)
  1977. {
  1978. var td = document.createElement("td");
  1979. var label = document.createElement("label");
  1980. var input = document.createElement("input");
  1981. input.type = "checkbox";
  1982. input.state = state;
  1983. input.addEventListener("click", clickListener.bind(this), false);
  1984. inputs.push(input);
  1985. label.appendChild(input);
  1986. label.appendChild(document.createTextNode(":" + state));
  1987. td.appendChild(label);
  1988. return td;
  1989. }
  1990.  
  1991. var tr = document.createElement("tr");
  1992. tr.appendChild(createCheckbox.call(this, "active"));
  1993. tr.appendChild(createCheckbox.call(this, "hover"));
  1994. table.appendChild(tr);
  1995.  
  1996. tr = document.createElement("tr");
  1997. tr.appendChild(createCheckbox.call(this, "focus"));
  1998. tr.appendChild(createCheckbox.call(this, "visited"));
  1999. table.appendChild(tr);
  2000.  
  2001. this._elementStatePane.appendChild(table);
  2002. },
  2003.  
  2004. _showUserAgentStylesSettingChanged: function()
  2005. {
  2006. this._rebuildUpdate();
  2007. },
  2008.  
  2009. willHide: function()
  2010. {
  2011. this._spectrumHelper.hide();
  2012. },
  2013.  
  2014. __proto__: WebInspector.SidebarPane.prototype
  2015. }
  2016.  
  2017.  
  2018. WebInspector.ComputedStyleSidebarPane = function()
  2019. {
  2020. WebInspector.SidebarPane.call(this, WebInspector.UIString("Computed Style"));
  2021. var showInheritedCheckbox = new WebInspector.Checkbox(WebInspector.UIString("Show inherited"), "sidebar-pane-subtitle");
  2022. this.titleElement.appendChild(showInheritedCheckbox.element);
  2023.  
  2024. if (WebInspector.settings.showInheritedComputedStyleProperties.get()) {
  2025. this.bodyElement.addStyleClass("show-inherited");
  2026. showInheritedCheckbox.checked = true;
  2027. }
  2028.  
  2029. function showInheritedToggleFunction(event)
  2030. {
  2031. WebInspector.settings.showInheritedComputedStyleProperties.set(showInheritedCheckbox.checked);
  2032. if (WebInspector.settings.showInheritedComputedStyleProperties.get())
  2033. this.bodyElement.addStyleClass("show-inherited");
  2034. else
  2035. this.bodyElement.removeStyleClass("show-inherited");
  2036. }
  2037.  
  2038. showInheritedCheckbox.addEventListener(showInheritedToggleFunction.bind(this));
  2039. }
  2040.  
  2041. WebInspector.ComputedStyleSidebarPane.prototype = {
  2042.  
  2043.  
  2044. expand: function()
  2045. {
  2046. function callback()
  2047. {
  2048. WebInspector.SidebarPane.prototype.expand.call(this);
  2049. }
  2050.  
  2051. this._stylesSidebarPane._refreshUpdate(null, true, callback.bind(this));
  2052. },
  2053.  
  2054. __proto__: WebInspector.SidebarPane.prototype
  2055. }
  2056.  
  2057.  
  2058. WebInspector.StylePropertiesSection = function(parentPane, styleRule, editable, isInherited, isFirstSection)
  2059. {
  2060. WebInspector.PropertiesSection.call(this, "");
  2061. this.element.className = "styles-section matched-styles monospace" + (isFirstSection ? " first-styles-section" : "");
  2062.  
  2063. if (styleRule.media) {
  2064. for (var i = styleRule.media.length - 1; i >= 0; --i) {
  2065. var media = styleRule.media[i];
  2066. var mediaDataElement = this.titleElement.createChild("div", "media");
  2067. var mediaText;
  2068. switch (media.source) {
  2069. case WebInspector.CSSMedia.Source.LINKED_SHEET:
  2070. case WebInspector.CSSMedia.Source.INLINE_SHEET:
  2071. mediaText = "media=\"" + media.text + "\"";
  2072. break;
  2073. case WebInspector.CSSMedia.Source.MEDIA_RULE:
  2074. mediaText = "@media " + media.text;
  2075. break;
  2076. case WebInspector.CSSMedia.Source.IMPORT_RULE:
  2077. mediaText = "@import " + media.text;
  2078. break;
  2079. }
  2080.  
  2081. if (media.sourceURL) {
  2082. var refElement = mediaDataElement.createChild("div", "subtitle");
  2083. var lineNumber = media.sourceLine < 0 ? undefined : media.sourceLine;
  2084. var anchor = WebInspector.linkifyResourceAsNode(media.sourceURL, lineNumber, "subtitle", media.sourceURL + (isNaN(lineNumber) ? "" : (":" + (lineNumber + 1))));
  2085. anchor.preferredPanel = "scripts";
  2086. anchor.style.float = "right";
  2087. refElement.appendChild(anchor);
  2088. }
  2089.  
  2090. var mediaTextElement = mediaDataElement.createChild("span");
  2091. mediaTextElement.textContent = mediaText;
  2092. mediaTextElement.title = media.text;
  2093. }
  2094. }
  2095.  
  2096. var selectorContainer = document.createElement("div");
  2097. this._selectorElement = document.createElement("span");
  2098. this._selectorElement.addStyleClass("selector-matches");
  2099. this._selectorElement.textContent = styleRule.selectorText;
  2100. selectorContainer.appendChild(this._selectorElement);
  2101.  
  2102. var openBrace = document.createElement("span");
  2103. openBrace.textContent = " {";
  2104. selectorContainer.appendChild(openBrace);
  2105. selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseDown.bind(this), false);
  2106. selectorContainer.addEventListener("click", this._handleSelectorContainerClick.bind(this), false);
  2107.  
  2108. var closeBrace = document.createElement("div");
  2109. closeBrace.textContent = "}";
  2110. this.element.appendChild(closeBrace);
  2111.  
  2112. this._selectorElement.addEventListener("click", this._handleSelectorClick.bind(this), false);
  2113. this.element.addEventListener("mousedown", this._handleEmptySpaceMouseDown.bind(this), false);
  2114. this.element.addEventListener("click", this._handleEmptySpaceClick.bind(this), false);
  2115.  
  2116. this._parentPane = parentPane;
  2117. this.styleRule = styleRule;
  2118. this.rule = this.styleRule.rule;
  2119. this.editable = editable;
  2120. this.isInherited = isInherited;
  2121.  
  2122. if (this.rule) {
  2123.  
  2124. if (this.rule.isUserAgent || this.rule.isUser)
  2125. this.editable = false;
  2126. this.titleElement.addStyleClass("styles-selector");
  2127. }
  2128.  
  2129. this._usedProperties = styleRule.usedProperties;
  2130.  
  2131. this._selectorRefElement = document.createElement("div");
  2132. this._selectorRefElement.className = "subtitle";
  2133. this._selectorRefElement.appendChild(this._createRuleOriginNode());
  2134. selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.firstChild);
  2135. this.titleElement.appendChild(selectorContainer);
  2136. this._selectorContainer = selectorContainer;
  2137.  
  2138. if (isInherited)
  2139. this.element.addStyleClass("show-inherited"); 
  2140.  
  2141. if (!this.editable)
  2142. this.element.addStyleClass("read-only");
  2143. }
  2144.  
  2145. WebInspector.StylePropertiesSection.prototype = {
  2146. get pane()
  2147. {
  2148. return this._parentPane;
  2149. },
  2150.  
  2151. collapse: function(dontRememberState)
  2152. {
  2153.  
  2154. },
  2155.  
  2156. isPropertyInherited: function(propertyName)
  2157. {
  2158. if (this.isInherited) {
  2159.  
  2160.  
  2161. return !(propertyName in WebInspector.CSSKeywordCompletions.InheritedProperties);
  2162. }
  2163. return false;
  2164. },
  2165.  
  2166.  
  2167. isPropertyOverloaded: function(propertyName, isShorthand)
  2168. {
  2169. if (!this._usedProperties || this.noAffect)
  2170. return false;
  2171.  
  2172. if (this.isInherited && !(propertyName in WebInspector.CSSKeywordCompletions.InheritedProperties)) {
  2173.  
  2174. return false;
  2175. }
  2176.  
  2177. var canonicalName = WebInspector.StylesSidebarPane.canonicalPropertyName(propertyName);
  2178. var used = (canonicalName in this._usedProperties);
  2179. if (used || !isShorthand)
  2180. return !used;
  2181.  
  2182.  
  2183.  
  2184. var longhandProperties = this.styleRule.style.longhandProperties(propertyName);
  2185. for (var j = 0; j < longhandProperties.length; ++j) {
  2186. var individualProperty = longhandProperties[j];
  2187. if (WebInspector.StylesSidebarPane.canonicalPropertyName(individualProperty.name) in this._usedProperties)
  2188. return false;
  2189. }
  2190.  
  2191. return true;
  2192. },
  2193.  
  2194. nextEditableSibling: function()
  2195. {
  2196. var curSection = this;
  2197. do {
  2198. curSection = curSection.nextSibling;
  2199. } while (curSection && !curSection.editable);
  2200.  
  2201. if (!curSection) {
  2202. curSection = this.firstSibling;
  2203. while (curSection && !curSection.editable)
  2204. curSection = curSection.nextSibling;
  2205. }
  2206.  
  2207. return (curSection && curSection.editable) ? curSection : null;
  2208. },
  2209.  
  2210. previousEditableSibling: function()
  2211. {
  2212. var curSection = this;
  2213. do {
  2214. curSection = curSection.previousSibling;
  2215. } while (curSection && !curSection.editable);
  2216.  
  2217. if (!curSection) {
  2218. curSection = this.lastSibling;
  2219. while (curSection && !curSection.editable)
  2220. curSection = curSection.previousSibling;
  2221. }
  2222.  
  2223. return (curSection && curSection.editable) ? curSection : null;
  2224. },
  2225.  
  2226. update: function(full)
  2227. {
  2228. if (full) {
  2229. this.propertiesTreeOutline.removeChildren();
  2230. this.populated = false;
  2231. } else {
  2232. var child = this.propertiesTreeOutline.children[0];
  2233. while (child) {
  2234. child.overloaded = this.isPropertyOverloaded(child.name, child.isShorthand);
  2235. child = child.traverseNextTreeElement(false, null, true);
  2236. }
  2237. }
  2238. this.afterUpdate();
  2239. },
  2240.  
  2241. afterUpdate: function()
  2242. {
  2243. if (this._afterUpdate) {
  2244. this._afterUpdate(this);
  2245. delete this._afterUpdate;
  2246. }
  2247. },
  2248.  
  2249. onpopulate: function()
  2250. {
  2251. var style = this.styleRule.style;
  2252. var allProperties = style.allProperties;
  2253. this.uniqueProperties = [];
  2254.  
  2255. var styleHasEditableSource = this.editable && !!style.range;
  2256. if (styleHasEditableSource) {
  2257. for (var i = 0; i < allProperties.length; ++i) {
  2258. var property = allProperties[i];
  2259. this.uniqueProperties.push(property);
  2260. if (property.styleBased)
  2261. continue;
  2262.  
  2263. var isShorthand = !!WebInspector.CSSCompletions.cssPropertiesMetainfo.longhands(property.name);
  2264. var inherited = this.isPropertyInherited(property.name);
  2265. var overloaded = property.inactive || this.isPropertyOverloaded(property.name);
  2266. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, isShorthand, inherited, overloaded);
  2267. this.propertiesTreeOutline.appendChild(item);
  2268. }
  2269. return;
  2270. }
  2271.  
  2272. var generatedShorthands = {};
  2273.  
  2274. for (var i = 0; i < allProperties.length; ++i) {
  2275. var property = allProperties[i];
  2276. this.uniqueProperties.push(property);
  2277. var isShorthand = !!WebInspector.CSSCompletions.cssPropertiesMetainfo.longhands(property.name);
  2278.  
  2279.  
  2280. var shorthands = isShorthand ? null : WebInspector.CSSCompletions.cssPropertiesMetainfo.shorthands(property.name);
  2281. var shorthandPropertyAvailable = false;
  2282. for (var j = 0; shorthands && !shorthandPropertyAvailable && j < shorthands.length; ++j) {
  2283. var shorthand = shorthands[j];
  2284. if (shorthand in generatedShorthands) {
  2285. shorthandPropertyAvailable = true;
  2286. continue;  
  2287. }
  2288. if (style.getLiveProperty(shorthand)) {
  2289. shorthandPropertyAvailable = true;
  2290. continue;  
  2291. }
  2292. if (!style.shorthandValue(shorthand)) {
  2293. shorthandPropertyAvailable = false;
  2294. continue;  
  2295. }
  2296.  
  2297.  
  2298. var shorthandProperty = new WebInspector.CSSProperty(style, style.allProperties.length, shorthand, style.shorthandValue(shorthand), "", "style", true, true, undefined);
  2299. var overloaded = property.inactive || this.isPropertyOverloaded(property.name, true);
  2300. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, shorthandProperty,    true,   false, overloaded);
  2301. this.propertiesTreeOutline.appendChild(item);
  2302. generatedShorthands[shorthand] = shorthandProperty;
  2303. shorthandPropertyAvailable = true;
  2304. }
  2305. if (shorthandPropertyAvailable)
  2306. continue;  
  2307.  
  2308. var inherited = this.isPropertyInherited(property.name);
  2309. var overloaded = property.inactive || this.isPropertyOverloaded(property.name, isShorthand);
  2310. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, isShorthand, inherited, overloaded);
  2311. this.propertiesTreeOutline.appendChild(item);
  2312. }
  2313. },
  2314.  
  2315. findTreeElementWithName: function(name)
  2316. {
  2317. var treeElement = this.propertiesTreeOutline.children[0];
  2318. while (treeElement) {
  2319. if (treeElement.name === name)
  2320. return treeElement;
  2321. treeElement = treeElement.traverseNextTreeElement(true, null, true);
  2322. }
  2323. return null;
  2324. },
  2325.  
  2326. _markSelectorMatches: function()
  2327. {
  2328. var rule = this.styleRule.rule;
  2329. if (!rule)
  2330. return;
  2331.  
  2332. var selectors = rule.selectors;
  2333. var matchingSelectors = rule.matchingSelectors;
  2334. if (selectors.length < 2 || !matchingSelectors)
  2335. return;
  2336.  
  2337. var fragment = document.createDocumentFragment();
  2338. var currentMatch = 0;
  2339. for (var i = 0, lastSelectorIndex = selectors.length - 1; i <= lastSelectorIndex ; ++i) {
  2340. var selectorNode;
  2341. var textNode = document.createTextNode(selectors[i]);
  2342. if (matchingSelectors[currentMatch] === i) {
  2343. ++currentMatch;
  2344. selectorNode = document.createElement("span");
  2345. selectorNode.className = "selector-matches";
  2346. selectorNode.appendChild(textNode);
  2347. } else
  2348. selectorNode = textNode;
  2349.  
  2350. fragment.appendChild(selectorNode);
  2351. if (i !== lastSelectorIndex)
  2352. fragment.appendChild(document.createTextNode(", "));
  2353. }
  2354.  
  2355. this._selectorElement.className = "selector";
  2356. this._selectorElement.removeChildren();
  2357. this._selectorElement.appendChild(fragment);
  2358. },
  2359.  
  2360. _checkWillCancelEditing: function()
  2361. {
  2362. var willCauseCancelEditing = this._willCauseCancelEditing;
  2363. delete this._willCauseCancelEditing;
  2364. return willCauseCancelEditing;
  2365. },
  2366.  
  2367. _handleSelectorContainerClick: function(event)
  2368. {
  2369. if (this._checkWillCancelEditing() || !this.editable)
  2370. return;
  2371. if (event.target === this._selectorContainer)
  2372. this.addNewBlankProperty(0).startEditing();
  2373. },
  2374.  
  2375.  
  2376. addNewBlankProperty: function(index)
  2377. {
  2378. var style = this.styleRule.style;
  2379. var property = style.newBlankProperty(index);
  2380. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, false, false, false);
  2381. index = property.index;
  2382. this.propertiesTreeOutline.insertChild(item, index);
  2383. item.listItemElement.textContent = "";
  2384. item._newProperty = true;
  2385. item.updateTitle();
  2386. return item;
  2387. },
  2388.  
  2389. _createRuleOriginNode: function()
  2390. {
  2391.  
  2392. function linkifyUncopyable(url, line)
  2393. {
  2394. var link = WebInspector.linkifyResourceAsNode(url, line, "", url + ":" + (line + 1));
  2395. link.preferredPanel = "scripts";
  2396. link.classList.add("webkit-html-resource-link");
  2397. link.setAttribute("data-uncopyable", link.textContent);
  2398. link.textContent = "";
  2399. return link;
  2400. }
  2401.  
  2402. if (this.styleRule.sourceURL)
  2403. return this._parentPane._linkifier.linkifyCSSRuleLocation(this.rule) || linkifyUncopyable(this.styleRule.sourceURL, this.rule.sourceLine);
  2404.  
  2405. if (!this.rule)
  2406. return document.createTextNode("");
  2407.  
  2408. var origin = "";
  2409. if (this.rule.isUserAgent)
  2410. return document.createTextNode(WebInspector.UIString("user agent stylesheet"));
  2411. if (this.rule.isUser)
  2412. return document.createTextNode(WebInspector.UIString("user stylesheet"));
  2413. if (this.rule.isViaInspector) {
  2414. var element = document.createElement("span");
  2415.  
  2416. function callback(resource)
  2417. {
  2418. if (resource)
  2419. element.appendChild(linkifyUncopyable(resource.url, this.rule.sourceLine));
  2420. else
  2421. element.textContent = WebInspector.UIString("via inspector");
  2422. }
  2423. WebInspector.cssModel.getViaInspectorResourceForRule(this.rule, callback.bind(this));
  2424. return element;
  2425. }
  2426. },
  2427.  
  2428. _handleEmptySpaceMouseDown: function(event)
  2429. {
  2430. this._willCauseCancelEditing = this._parentPane._isEditingStyle;
  2431. },
  2432.  
  2433. _handleEmptySpaceClick: function(event)
  2434. {
  2435. if (!this.editable)
  2436. return;
  2437.  
  2438. if (!window.getSelection().isCollapsed)
  2439. return;
  2440.  
  2441. if (this._checkWillCancelEditing())
  2442. return;
  2443.  
  2444. if (event.target.hasStyleClass("header") || this.element.hasStyleClass("read-only") || event.target.enclosingNodeOrSelfWithClass("media")) {
  2445. event.consume();
  2446. return;
  2447. }
  2448. this.expand();
  2449. this.addNewBlankProperty().startEditing();
  2450. },
  2451.  
  2452. _handleSelectorClick: function(event)
  2453. {
  2454. this._startEditingOnMouseEvent();
  2455. event.consume(true);
  2456. },
  2457.  
  2458. _startEditingOnMouseEvent: function()
  2459. {
  2460. if (!this.editable)
  2461. return;
  2462.  
  2463. if (!this.rule && this.propertiesTreeOutline.children.length === 0) {
  2464. this.expand();
  2465. this.addNewBlankProperty().startEditing();
  2466. return;
  2467. }
  2468.  
  2469. if (!this.rule)
  2470. return;
  2471.  
  2472. this.startEditingSelector();
  2473. },
  2474.  
  2475. startEditingSelector: function()
  2476. {
  2477. var element = this._selectorElement;
  2478. if (WebInspector.isBeingEdited(element))
  2479. return;
  2480.  
  2481. element.scrollIntoViewIfNeeded(false);
  2482. element.textContent = element.textContent; 
  2483.  
  2484. var config = new WebInspector.EditingConfig(this.editingSelectorCommitted.bind(this), this.editingSelectorCancelled.bind(this));
  2485. WebInspector.startEditing(this._selectorElement, config);
  2486.  
  2487. window.getSelection().setBaseAndExtent(element, 0, element, 1);
  2488. },
  2489.  
  2490. _moveEditorFromSelector: function(moveDirection)
  2491. {
  2492. this._markSelectorMatches();
  2493.  
  2494. if (!moveDirection)
  2495. return;
  2496.  
  2497. if (moveDirection === "forward") {
  2498. this.expand();
  2499. var firstChild = this.propertiesTreeOutline.children[0];
  2500. while (firstChild && firstChild.inherited)
  2501. firstChild = firstChild.nextSibling;
  2502. if (!firstChild)
  2503. this.addNewBlankProperty().startEditing();
  2504. else
  2505. firstChild.startEditing(firstChild.nameElement);
  2506. } else {
  2507. var previousSection = this.previousEditableSibling();
  2508. if (!previousSection)
  2509. return;
  2510.  
  2511. previousSection.expand();
  2512. previousSection.addNewBlankProperty().startEditing();
  2513. }
  2514. },
  2515.  
  2516. editingSelectorCommitted: function(element, newContent, oldContent, context, moveDirection)
  2517. {
  2518. if (newContent)
  2519. newContent = newContent.trim();
  2520. if (newContent === oldContent) {
  2521.  
  2522. this._selectorElement.textContent = newContent;
  2523. return this._moveEditorFromSelector(moveDirection);
  2524. }
  2525.  
  2526. function successCallback(newRule, doesAffectSelectedNode)
  2527. {
  2528. if (!doesAffectSelectedNode) {
  2529. this.noAffect = true;
  2530. this.element.addStyleClass("no-affect");
  2531. } else {
  2532. delete this.noAffect;
  2533. this.element.removeStyleClass("no-affect");
  2534. }
  2535.  
  2536. this.rule = newRule;
  2537. this.styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, media: newRule.media, sourceURL: newRule.sourceURL, rule: newRule };
  2538.  
  2539. this._parentPane.update();
  2540.  
  2541. this._moveEditorFromSelector(moveDirection);
  2542. }
  2543.  
  2544. var selectedNode = this._parentPane.node;
  2545. WebInspector.cssModel.setRuleSelector(this.rule.id, selectedNode ? selectedNode.id : 0, newContent, successCallback.bind(this), this._moveEditorFromSelector.bind(this, moveDirection));
  2546. },
  2547.  
  2548. editingSelectorCancelled: function()
  2549. {
  2550.  
  2551.  
  2552. this._markSelectorMatches();
  2553. },
  2554.  
  2555. __proto__: WebInspector.PropertiesSection.prototype
  2556. }
  2557.  
  2558.  
  2559. WebInspector.ComputedStylePropertiesSection = function(parentPane, styleRule, usedProperties)
  2560. {
  2561. WebInspector.PropertiesSection.call(this, "");
  2562. this.headerElement.addStyleClass("hidden");
  2563. this.element.className = "styles-section monospace first-styles-section read-only computed-style";
  2564. this._parentPane = parentPane;
  2565. this.styleRule = styleRule;
  2566. this._usedProperties = usedProperties;
  2567. this._alwaysShowComputedProperties = { "display": true, "height": true, "width": true };
  2568. this.computedStyle = true;
  2569. this._propertyTreeElements = {};
  2570. this._expandedPropertyNames = {};
  2571. }
  2572.  
  2573. WebInspector.ComputedStylePropertiesSection.prototype = {
  2574. get pane()
  2575. {
  2576. return this._parentPane;
  2577. },
  2578.  
  2579. collapse: function(dontRememberState)
  2580. {
  2581.  
  2582. },
  2583.  
  2584. _isPropertyInherited: function(propertyName)
  2585. {
  2586. var canonicalName = WebInspector.StylesSidebarPane.canonicalPropertyName(propertyName);
  2587. return !(canonicalName in this._usedProperties) && !(canonicalName in this._alwaysShowComputedProperties);
  2588. },
  2589.  
  2590. update: function()
  2591. {
  2592. this._expandedPropertyNames = {};
  2593. for (var name in this._propertyTreeElements) {
  2594. if (this._propertyTreeElements[name].expanded)
  2595. this._expandedPropertyNames[name] = true;
  2596. }
  2597. this._propertyTreeElements = {};
  2598. this.propertiesTreeOutline.removeChildren();
  2599. this.populated = false;
  2600. },
  2601.  
  2602. onpopulate: function()
  2603. {
  2604. function sorter(a, b)
  2605. {
  2606. return a.name.localeCompare(b.name);
  2607. }
  2608.  
  2609. var style = this.styleRule.style;
  2610. if (!style)
  2611. return;
  2612.  
  2613. var uniqueProperties = [];
  2614. var allProperties = style.allProperties;
  2615. for (var i = 0; i < allProperties.length; ++i)
  2616. uniqueProperties.push(allProperties[i]);
  2617. uniqueProperties.sort(sorter);
  2618.  
  2619. this._propertyTreeElements = {};
  2620. for (var i = 0; i < uniqueProperties.length; ++i) {
  2621. var property = uniqueProperties[i];
  2622. var inherited = this._isPropertyInherited(property.name);
  2623. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, false, inherited, false);
  2624. this.propertiesTreeOutline.appendChild(item);
  2625. this._propertyTreeElements[property.name] = item;
  2626. }
  2627. },
  2628.  
  2629. rebuildComputedTrace: function(sections)
  2630. {
  2631. for (var i = 0; i < sections.length; ++i) {
  2632. var section = sections[i];
  2633. if (section.computedStyle || section.isBlank)
  2634. continue;
  2635.  
  2636. for (var j = 0; j < section.uniqueProperties.length; ++j) {
  2637. var property = section.uniqueProperties[j];
  2638. if (property.disabled)
  2639. continue;
  2640. if (section.isInherited && !(property.name in WebInspector.CSSKeywordCompletions.InheritedProperties))
  2641. continue;
  2642.  
  2643. var treeElement = this._propertyTreeElements[property.name];
  2644. if (treeElement) {
  2645. var fragment = document.createDocumentFragment();
  2646. var selector = fragment.createChild("span");
  2647. selector.style.color = "gray";
  2648. selector.textContent = section.styleRule.selectorText;
  2649. fragment.appendChild(document.createTextNode(" - " + property.value + " "));
  2650. var subtitle = fragment.createChild("span");
  2651. subtitle.style.float = "right";
  2652. subtitle.appendChild(section._createRuleOriginNode());
  2653. var childElement = new TreeElement(fragment, null, false);
  2654. treeElement.appendChild(childElement);
  2655. if (property.inactive || section.isPropertyOverloaded(property.name))
  2656. childElement.listItemElement.addStyleClass("overloaded");
  2657. if (!property.parsedOk) {
  2658. childElement.listItemElement.addStyleClass("not-parsed-ok");
  2659. childElement.listItemElement.insertBefore(WebInspector.StylesSidebarPane.createExclamationMark(property.name), childElement.listItemElement.firstChild);
  2660. }
  2661. }
  2662. }
  2663. }
  2664.  
  2665.  
  2666. for (var name in this._expandedPropertyNames) {
  2667. if (name in this._propertyTreeElements)
  2668. this._propertyTreeElements[name].expand();
  2669. }
  2670. },
  2671.  
  2672. __proto__: WebInspector.PropertiesSection.prototype
  2673. }
  2674.  
  2675.  
  2676. WebInspector.BlankStylePropertiesSection = function(parentPane, defaultSelectorText)
  2677. {
  2678. WebInspector.StylePropertiesSection.call(this, parentPane, {selectorText: defaultSelectorText, rule: {isViaInspector: true}}, true, false, false);
  2679. this.element.addStyleClass("blank-section");
  2680. }
  2681.  
  2682. WebInspector.BlankStylePropertiesSection.prototype = {
  2683. get isBlank()
  2684. {
  2685. return !this._normal;
  2686. },
  2687.  
  2688. expand: function()
  2689. {
  2690. if (!this.isBlank)
  2691. WebInspector.StylePropertiesSection.prototype.expand.call(this);
  2692. },
  2693.  
  2694. editingSelectorCommitted: function(element, newContent, oldContent, context, moveDirection)
  2695. {
  2696. if (!this.isBlank) {
  2697. WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted.call(this, element, newContent, oldContent, context, moveDirection);
  2698. return;
  2699. }
  2700.  
  2701. function successCallback(newRule, doesSelectorAffectSelectedNode)
  2702. {
  2703. var styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, sourceURL: newRule.sourceURL, rule: newRule };
  2704. this.makeNormal(styleRule);
  2705.  
  2706. if (!doesSelectorAffectSelectedNode) {
  2707. this.noAffect = true;
  2708. this.element.addStyleClass("no-affect");
  2709. }
  2710.  
  2711. this._selectorRefElement.removeChildren();
  2712. this._selectorRefElement.appendChild(this._createRuleOriginNode());
  2713. this.expand();
  2714. if (this.element.parentElement) 
  2715. this._moveEditorFromSelector(moveDirection);
  2716.  
  2717. delete this._parentPane._userOperation;
  2718. }
  2719.  
  2720. this._parentPane._userOperation = true;
  2721. WebInspector.cssModel.addRule(this.pane.node.id, newContent, successCallback.bind(this), this.editingSelectorCancelled.bind(this));
  2722. },
  2723.  
  2724. editingSelectorCancelled: function()
  2725. {
  2726. if (!this.isBlank) {
  2727. WebInspector.StylePropertiesSection.prototype.editingSelectorCancelled.call(this);
  2728. return;
  2729. }
  2730.  
  2731. this.pane.removeSection(this);
  2732. },
  2733.  
  2734. makeNormal: function(styleRule)
  2735. {
  2736. this.element.removeStyleClass("blank-section");
  2737. this.styleRule = styleRule;
  2738. this.rule = styleRule.rule;
  2739.  
  2740.  
  2741. this._normal = true;
  2742. },
  2743.  
  2744. __proto__: WebInspector.StylePropertiesSection.prototype
  2745. }
  2746.  
  2747.  
  2748. WebInspector.StylePropertyTreeElement = function(section, parentPane, styleRule, style, property, isShorthand, inherited, overloaded)
  2749. {
  2750. this.section = section;
  2751. this._parentPane = parentPane;
  2752. this._styleRule = styleRule;
  2753. this.style = style;
  2754. this.property = property;
  2755. this.isShorthand = isShorthand;
  2756. this._inherited = inherited;
  2757. this._overloaded = overloaded;
  2758.  
  2759.  
  2760. TreeElement.call(this, "", null, isShorthand);
  2761.  
  2762. this.selectable = false;
  2763. }
  2764.  
  2765. WebInspector.StylePropertyTreeElement.prototype = {
  2766. get inherited()
  2767. {
  2768. return this._inherited;
  2769. },
  2770.  
  2771. set inherited(x)
  2772. {
  2773. if (x === this._inherited)
  2774. return;
  2775. this._inherited = x;
  2776. this.updateState();
  2777. },
  2778.  
  2779. get overloaded()
  2780. {
  2781. return this._overloaded;
  2782. },
  2783.  
  2784. set overloaded(x)
  2785. {
  2786. if (x === this._overloaded)
  2787. return;
  2788. this._overloaded = x;
  2789. this.updateState();
  2790. },
  2791.  
  2792. get disabled()
  2793. {
  2794. return this.property.disabled;
  2795. },
  2796.  
  2797. get name()
  2798. {
  2799. if (!this.disabled || !this.property.text)
  2800. return this.property.name;
  2801.  
  2802. var text = this.property.text;
  2803. var index = text.indexOf(":");
  2804. if (index < 1)
  2805. return this.property.name;
  2806.  
  2807. return text.substring(0, index).trim();
  2808. },
  2809.  
  2810. get priority()
  2811. {
  2812. if (this.disabled)
  2813. return ""; 
  2814. return this.property.priority;
  2815. },
  2816.  
  2817. get value()
  2818. {
  2819. if (!this.disabled || !this.property.text)
  2820. return this.property.value;
  2821.  
  2822. var match = this.property.text.match(/(.*);\s*/);
  2823. if (!match || !match[1])
  2824. return this.property.value;
  2825.  
  2826. var text = match[1];
  2827. var index = text.indexOf(":");
  2828. if (index < 1)
  2829. return this.property.value;
  2830.  
  2831. return text.substring(index + 1).trim();
  2832. },
  2833.  
  2834. get parsedOk()
  2835. {
  2836. return this.property.parsedOk;
  2837. },
  2838.  
  2839. onattach: function()
  2840. {
  2841. this.updateTitle();
  2842. this.listItemElement.addEventListener("mousedown", this._mouseDown.bind(this));
  2843. this.listItemElement.addEventListener("mouseup", this._resetMouseDownElement.bind(this));
  2844. this.listItemElement.addEventListener("click", this._mouseClick.bind(this));
  2845. },
  2846.  
  2847. _mouseDown: function(event)
  2848. {
  2849. if (this._parentPane) {
  2850. this._parentPane._mouseDownTreeElement = this;
  2851. this._parentPane._mouseDownTreeElementIsName = this._isNameElement(event.target);
  2852. this._parentPane._mouseDownTreeElementIsValue = this._isValueElement(event.target);
  2853. }
  2854. },
  2855.  
  2856. _resetMouseDownElement: function()
  2857. {
  2858. if (this._parentPane) {
  2859. delete this._parentPane._mouseDownTreeElement;
  2860. delete this._parentPane._mouseDownTreeElementIsName;
  2861. delete this._parentPane._mouseDownTreeElementIsValue;
  2862. }
  2863. },
  2864.  
  2865. updateTitle: function()
  2866. {
  2867. var value = this.value;
  2868.  
  2869. this.updateState();
  2870.  
  2871. var enabledCheckboxElement;
  2872. if (this.parsedOk) {
  2873. enabledCheckboxElement = document.createElement("input");
  2874. enabledCheckboxElement.className = "enabled-button";
  2875. enabledCheckboxElement.type = "checkbox";
  2876. enabledCheckboxElement.checked = !this.disabled;
  2877. enabledCheckboxElement.addEventListener("click", this.toggleEnabled.bind(this), false);
  2878. }
  2879.  
  2880. var nameElement = document.createElement("span");
  2881. nameElement.className = "webkit-css-property";
  2882. nameElement.textContent = this.name;
  2883. nameElement.title = this.property.propertyText;
  2884. this.nameElement = nameElement;
  2885.  
  2886. this._expandElement = document.createElement("span");
  2887. this._expandElement.className = "expand-element";
  2888.  
  2889. var valueElement = document.createElement("span");
  2890. valueElement.className = "value";
  2891. this.valueElement = valueElement;
  2892.  
  2893. var cf = WebInspector.Color.Format;
  2894.  
  2895. if (value) {
  2896. var self = this;
  2897.  
  2898. function processValue(regex, processor, nextProcessor, valueText)
  2899. {
  2900. var container = document.createDocumentFragment();
  2901.  
  2902. var items = valueText.replace(regex, "\0$1\0").split("\0");
  2903. for (var i = 0; i < items.length; ++i) {
  2904. if ((i % 2) === 0) {
  2905. if (nextProcessor)
  2906. container.appendChild(nextProcessor(items[i]));
  2907. else
  2908. container.appendChild(document.createTextNode(items[i]));
  2909. } else {
  2910. var processedNode = processor(items[i]);
  2911. if (processedNode)
  2912. container.appendChild(processedNode);
  2913. }
  2914. }
  2915.  
  2916. return container;
  2917. }
  2918.  
  2919. function linkifyURL(url)
  2920. {
  2921. var hrefUrl = url;
  2922. var match = hrefUrl.match(/['"]?([^'"]+)/);
  2923. if (match)
  2924. hrefUrl = match[1];
  2925. var container = document.createDocumentFragment();
  2926. container.appendChild(document.createTextNode("url("));
  2927. if (self._styleRule.sourceURL)
  2928. hrefUrl = WebInspector.ParsedURL.completeURL(self._styleRule.sourceURL, hrefUrl);
  2929. else if (self._parentPane.node)
  2930. hrefUrl = self._parentPane.node.resolveURL(hrefUrl);
  2931. var hasResource = !!WebInspector.resourceForURL(hrefUrl);
  2932.  
  2933. container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl, url, undefined, !hasResource));
  2934. container.appendChild(document.createTextNode(")"));
  2935. return container;
  2936. }
  2937.  
  2938. function processColor(text)
  2939. {
  2940. try {
  2941. var color = new WebInspector.Color(text);
  2942. } catch (e) {
  2943. return document.createTextNode(text);
  2944. }
  2945.  
  2946. var format = getFormat();
  2947. var hasSpectrum = self._parentPane;
  2948. var spectrumHelper = hasSpectrum ? self._parentPane._spectrumHelper : null;
  2949. var spectrum = spectrumHelper ? spectrumHelper.spectrum() : null;
  2950.  
  2951. var colorSwatch = new WebInspector.ColorSwatch();
  2952. colorSwatch.setColorString(text);
  2953. colorSwatch.element.addEventListener("click", swatchClick, false);
  2954.  
  2955. var scrollerElement = hasSpectrum ? self._parentPane._computedStylePane.element.parentElement : null;
  2956.  
  2957. function spectrumChanged(e)
  2958. {
  2959. color = e.data;
  2960. var colorString = color.toString();
  2961. colorValueElement.textContent = colorString;
  2962. colorSwatch.setColorString(colorString);
  2963. self.applyStyleText(nameElement.textContent + ": " + valueElement.textContent, false, false, false);
  2964. }
  2965.  
  2966. function spectrumHidden(event)
  2967. {
  2968. scrollerElement.removeEventListener("scroll", repositionSpectrum, false);
  2969. var commitEdit = event.data;
  2970. var propertyText = !commitEdit && self.originalPropertyText ? self.originalPropertyText : (nameElement.textContent + ": " + valueElement.textContent);
  2971. self.applyStyleText(propertyText, true, true, false);
  2972. spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorChanged, spectrumChanged);
  2973. spectrumHelper.removeEventListener(WebInspector.SpectrumPopupHelper.Events.Hidden, spectrumHidden);
  2974.  
  2975. delete self._parentPane._isEditingStyle;
  2976. delete self.originalPropertyText;
  2977. }
  2978.  
  2979. function repositionSpectrum()
  2980. {
  2981. spectrumHelper.reposition(colorSwatch.element);
  2982. }
  2983.  
  2984. function swatchClick(e)
  2985. {
  2986.  
  2987.  
  2988. if (!spectrumHelper || e.shiftKey)
  2989. changeColorDisplay(e);
  2990. else {
  2991. var visible = spectrumHelper.toggle(colorSwatch.element, color, format);
  2992.  
  2993. if (visible) {
  2994. spectrum.displayText = color.toString(format);
  2995. self.originalPropertyText = self.property.propertyText;
  2996. self._parentPane._isEditingStyle = true;
  2997. spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChanged, spectrumChanged);
  2998. spectrumHelper.addEventListener(WebInspector.SpectrumPopupHelper.Events.Hidden, spectrumHidden);
  2999.  
  3000. scrollerElement.addEventListener("scroll", repositionSpectrum, false);
  3001. }
  3002. }
  3003. e.consume(true);
  3004. }
  3005.  
  3006. function getFormat()
  3007. {
  3008. var format;
  3009. var formatSetting = WebInspector.settings.colorFormat.get();
  3010. if (formatSetting === cf.Original)
  3011. format = cf.Original;
  3012. else if (color.nickname)
  3013. format = cf.Nickname;
  3014. else if (formatSetting === cf.RGB)
  3015. format = (color.simple ? cf.RGB : cf.RGBA);
  3016. else if (formatSetting === cf.HSL)
  3017. format = (color.simple ? cf.HSL : cf.HSLA);
  3018. else if (color.simple)
  3019. format = (color.hasShortHex() ? cf.ShortHEX : cf.HEX);
  3020. else
  3021. format = cf.RGBA;
  3022.  
  3023. return format;
  3024. }
  3025.  
  3026. var colorValueElement = document.createElement("span");
  3027. colorValueElement.textContent = color.toString(format);
  3028.  
  3029. function nextFormat(curFormat)
  3030. {
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039. switch (curFormat) {
  3040. case cf.Original:
  3041. return color.simple ? cf.RGB : cf.RGBA;
  3042.  
  3043. case cf.RGB:
  3044. case cf.RGBA:
  3045. return color.simple ? cf.HSL : cf.HSLA;
  3046.  
  3047. case cf.HSL:
  3048. case cf.HSLA:
  3049. if (color.nickname)
  3050. return cf.Nickname;
  3051. if (color.simple)
  3052. return color.hasShortHex() ? cf.ShortHEX : cf.HEX;
  3053. else
  3054. return cf.Original;
  3055.  
  3056. case cf.ShortHEX:
  3057. return cf.HEX;
  3058.  
  3059. case cf.HEX:
  3060. return cf.Original;
  3061.  
  3062. case cf.Nickname:
  3063. if (color.simple)
  3064. return color.hasShortHex() ? cf.ShortHEX : cf.HEX;
  3065. else
  3066. return cf.Original;
  3067.  
  3068. default:
  3069. return null;
  3070. }
  3071. }
  3072.  
  3073. function changeColorDisplay(event)
  3074. {
  3075. do {
  3076. format = nextFormat(format);
  3077. var currentValue = color.toString(format || "");
  3078. } while (format && currentValue === color.value && format !== cf.Original);
  3079.  
  3080. if (format)
  3081. colorValueElement.textContent = currentValue;
  3082. }
  3083.  
  3084. var container = document.createElement("nobr");
  3085. container.appendChild(colorSwatch.element);
  3086. container.appendChild(colorValueElement);
  3087. return container;
  3088. }
  3089.  
  3090. var colorRegex = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}|\b\w+\b(?!-))/g;
  3091. var colorProcessor = processValue.bind(window, colorRegex, processColor, null);
  3092.  
  3093. valueElement.appendChild(processValue(/url\(\s*([^)\s]+)\s*\)/g, linkifyURL.bind(this), WebInspector.CSSKeywordCompletions.isColorAwareProperty(self.name) ? colorProcessor : null, value));
  3094. }
  3095.  
  3096. this.listItemElement.removeChildren();
  3097. nameElement.normalize();
  3098. valueElement.normalize();
  3099.  
  3100. if (!this.treeOutline)
  3101. return;
  3102.  
  3103.  
  3104. if (enabledCheckboxElement && this.treeOutline.section && this.parent.root && !this.section.computedStyle)
  3105. this.listItemElement.appendChild(enabledCheckboxElement);
  3106. this.listItemElement.appendChild(nameElement);
  3107. this.listItemElement.appendChild(document.createTextNode(": "));
  3108. this.listItemElement.appendChild(this._expandElement);
  3109. this.listItemElement.appendChild(valueElement);
  3110. this.listItemElement.appendChild(document.createTextNode(";"));
  3111.  
  3112. if (!this.parsedOk) {
  3113.  
  3114. this.hasChildren = false;
  3115. this.listItemElement.addStyleClass("not-parsed-ok");
  3116.  
  3117.  
  3118. this.listItemElement.insertBefore(WebInspector.StylesSidebarPane.createExclamationMark(this.property.name), this.listItemElement.firstChild);
  3119. }
  3120. if (this.property.inactive)
  3121. this.listItemElement.addStyleClass("inactive");
  3122. },
  3123.  
  3124. _updatePane: function(userCallback)
  3125. {
  3126. if (this.treeOutline && this.treeOutline.section && this.treeOutline.section.pane)
  3127. this.treeOutline.section.pane._refreshUpdate(this.treeOutline.section, false, userCallback);
  3128. else  {
  3129. if (userCallback)
  3130. userCallback();
  3131. }
  3132. },
  3133.  
  3134. toggleEnabled: function(event)
  3135. {
  3136. var disabled = !event.target.checked;
  3137.  
  3138. function callback(newStyle)
  3139. {
  3140. if (!newStyle)
  3141. return;
  3142.  
  3143. this.style = newStyle;
  3144. this._styleRule.style = newStyle;
  3145.  
  3146. if (this.treeOutline.section && this.treeOutline.section.pane)
  3147. this.treeOutline.section.pane.dispatchEventToListeners("style property toggled");
  3148.  
  3149. this._updatePane();
  3150.  
  3151. delete this._parentPane._userOperation;
  3152. }
  3153.  
  3154. this._parentPane._userOperation = true;
  3155. this.property.setDisabled(disabled, callback.bind(this));
  3156. event.consume();
  3157. },
  3158.  
  3159. updateState: function()
  3160. {
  3161. if (!this.listItemElement)
  3162. return;
  3163.  
  3164. if (this.style.isPropertyImplicit(this.name) || this.value === "initial")
  3165. this.listItemElement.addStyleClass("implicit");
  3166. else
  3167. this.listItemElement.removeStyleClass("implicit");
  3168.  
  3169. if (this.inherited)
  3170. this.listItemElement.addStyleClass("inherited");
  3171. else
  3172. this.listItemElement.removeStyleClass("inherited");
  3173.  
  3174. if (this.overloaded)
  3175. this.listItemElement.addStyleClass("overloaded");
  3176. else
  3177. this.listItemElement.removeStyleClass("overloaded");
  3178.  
  3179. if (this.disabled)
  3180. this.listItemElement.addStyleClass("disabled");
  3181. else
  3182. this.listItemElement.removeStyleClass("disabled");
  3183. },
  3184.  
  3185. onpopulate: function()
  3186. {
  3187.  
  3188. if (this.children.length || !this.isShorthand)
  3189. return;
  3190.  
  3191. var longhandProperties = this.style.longhandProperties(this.name);
  3192. for (var i = 0; i < longhandProperties.length; ++i) {
  3193. var name = longhandProperties[i].name;
  3194.  
  3195. if (this.treeOutline.section) {
  3196. var inherited = this.treeOutline.section.isPropertyInherited(name);
  3197. var overloaded = this.treeOutline.section.isPropertyOverloaded(name);
  3198. }
  3199.  
  3200. var liveProperty = this.style.getLiveProperty(name);
  3201. if (!liveProperty)
  3202. continue;
  3203.  
  3204. var item = new WebInspector.StylePropertyTreeElement(this.section, this._parentPane, this._styleRule, this.style, liveProperty, false, inherited, overloaded);
  3205. this.appendChild(item);
  3206. }
  3207. },
  3208.  
  3209. restoreNameElement: function()
  3210. {
  3211.  
  3212. if (this.nameElement === this.listItemElement.querySelector(".webkit-css-property"))
  3213. return;
  3214.  
  3215. this.nameElement = document.createElement("span");
  3216. this.nameElement.className = "webkit-css-property";
  3217. this.nameElement.textContent = "";
  3218. this.listItemElement.insertBefore(this.nameElement, this.listItemElement.firstChild);
  3219. },
  3220.  
  3221. _mouseClick: function(event)
  3222. {
  3223. if (!window.getSelection().isCollapsed)
  3224. return;
  3225.  
  3226. event.consume(true);
  3227.  
  3228. if (event.target === this.listItemElement) {
  3229. if (!this.section.editable) 
  3230. return;
  3231.  
  3232. if (this.section._checkWillCancelEditing())
  3233. return;
  3234. this.section.addNewBlankProperty(this.property.index + 1).startEditing();
  3235. return;
  3236. }
  3237.  
  3238. this.startEditing(event.target);
  3239. },
  3240.  
  3241. _isNameElement: function(element)
  3242. {
  3243. return element.enclosingNodeOrSelfWithClass("webkit-css-property") === this.nameElement;
  3244. },
  3245.  
  3246. _isValueElement: function(element)
  3247. {
  3248. return !!element.enclosingNodeOrSelfWithClass("value");
  3249. },
  3250.  
  3251. startEditing: function(selectElement)
  3252. {
  3253.  
  3254. if (this.parent.isShorthand)
  3255. return;
  3256.  
  3257. if (selectElement === this._expandElement)
  3258. return;
  3259.  
  3260. if (this.treeOutline.section && !this.treeOutline.section.editable)
  3261. return;
  3262.  
  3263. if (!selectElement)
  3264. selectElement = this.nameElement; 
  3265. else
  3266. selectElement = selectElement.enclosingNodeOrSelfWithClass("webkit-css-property") || selectElement.enclosingNodeOrSelfWithClass("value");
  3267.  
  3268. var isEditingName = selectElement === this.nameElement;
  3269. if (!isEditingName && selectElement !== this.valueElement) {
  3270.  
  3271. isEditingName = false;
  3272. selectElement = this.valueElement;
  3273. }
  3274.  
  3275. if (WebInspector.isBeingEdited(selectElement))
  3276. return;
  3277.  
  3278. var context = {
  3279. expanded: this.expanded,
  3280. hasChildren: this.hasChildren,
  3281. isEditingName: isEditingName,
  3282. previousContent: selectElement.textContent
  3283. };
  3284.  
  3285.  
  3286. this.hasChildren = false;
  3287.  
  3288. if (selectElement.parentElement)
  3289. selectElement.parentElement.addStyleClass("child-editing");
  3290. selectElement.textContent = selectElement.textContent; 
  3291.  
  3292. function pasteHandler(context, event)
  3293. {
  3294. var data = event.clipboardData.getData("Text");
  3295. if (!data)
  3296. return;
  3297. var colonIdx = data.indexOf(":");
  3298. if (colonIdx < 0)
  3299. return;
  3300. var name = data.substring(0, colonIdx).trim();
  3301. var value = data.substring(colonIdx + 1).trim();
  3302.  
  3303. event.preventDefault();
  3304.  
  3305. if (!("originalName" in context)) {
  3306. context.originalName = this.nameElement.textContent;
  3307. context.originalValue = this.valueElement.textContent;
  3308. }
  3309. this.nameElement.textContent = name;
  3310. this.valueElement.textContent = value;
  3311. this.nameElement.normalize();
  3312. this.valueElement.normalize();
  3313.  
  3314. this.editingCommitted(null, event.target.textContent, context.previousContent, context, "forward");
  3315. }
  3316.  
  3317. function blurListener(context, event)
  3318. {
  3319. var treeElement = this._parentPane._mouseDownTreeElement;
  3320. var moveDirection = "";
  3321. if (treeElement === this) {
  3322. if (isEditingName && this._parentPane._mouseDownTreeElementIsValue)
  3323. moveDirection = "forward";
  3324. if (!isEditingName && this._parentPane._mouseDownTreeElementIsName)
  3325. moveDirection = "backward";
  3326. }
  3327. this.editingCommitted(null, event.target.textContent, context.previousContent, context, moveDirection);
  3328. }
  3329.  
  3330. delete this.originalPropertyText;
  3331.  
  3332. this._parentPane._isEditingStyle = true;
  3333. if (selectElement.parentElement)
  3334. selectElement.parentElement.scrollIntoViewIfNeeded(false);
  3335.  
  3336. var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bind(this, true) : undefined;
  3337. this._prompt = new WebInspector.StylesSidebarPane.CSSPropertyPrompt(isEditingName ? WebInspector.CSSCompletions.cssPropertiesMetainfo : WebInspector.CSSKeywordCompletions.forProperty(this.nameElement.textContent), this, isEditingName);
  3338. if (applyItemCallback) {
  3339. this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemApplied, applyItemCallback, this);
  3340. this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemAccepted, applyItemCallback, this);
  3341. }
  3342. var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurListener.bind(this, context));
  3343.  
  3344. proxyElement.addEventListener("keydown", this.editingNameValueKeyDown.bind(this, context), false);
  3345. if (isEditingName)
  3346. proxyElement.addEventListener("paste", pasteHandler.bind(this, context));
  3347.  
  3348. window.getSelection().setBaseAndExtent(selectElement, 0, selectElement, 1);
  3349. },
  3350.  
  3351. editingNameValueKeyDown: function(context, event)
  3352. {
  3353. if (event.handled)
  3354. return;
  3355.  
  3356. var isEditingName = context.isEditingName;
  3357. var result;
  3358.  
  3359. function shouldCommitValueSemicolon(text, cursorPosition)
  3360. {
  3361.  
  3362. var openQuote = "";
  3363. for (var i = 0; i < cursorPosition; ++i) {
  3364. var ch = text[i];
  3365. if (ch === "\\" && openQuote !== "")
  3366. ++i; 
  3367. else if (!openQuote && (ch === "\"" || ch === "'"))
  3368. openQuote = ch;
  3369. else if (openQuote === ch)
  3370. openQuote = "";
  3371. }
  3372. return !openQuote;
  3373. }
  3374.  
  3375.  
  3376. var isFieldInputTerminated = (event.keyCode === WebInspector.KeyboardShortcut.Keys.Semicolon.code) &&
  3377. (isEditingName ? event.shiftKey : (!event.shiftKey && shouldCommitValueSemicolon(event.target.textContent, event.target.selectionLeftOffset())));
  3378. if (isEnterKey(event) || isFieldInputTerminated) {
  3379.  
  3380. event.preventDefault();
  3381. result = "forward";
  3382. } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || event.keyIdentifier === "U+001B")
  3383. result = "cancel";
  3384. else if (!isEditingName && this._newProperty && event.keyCode === WebInspector.KeyboardShortcut.Keys.Backspace.code) {
  3385.  
  3386. var selection = window.getSelection();
  3387. if (selection.isCollapsed && !selection.focusOffset) {
  3388. event.preventDefault();
  3389. result = "backward";
  3390. }
  3391. } else if (event.keyIdentifier === "U+0009") { 
  3392. result = event.shiftKey ? "backward" : "forward";
  3393. event.preventDefault();
  3394. }
  3395.  
  3396. if (result) {
  3397. switch (result) {
  3398. case "cancel":
  3399. this.editingCancelled(null, context);
  3400. break;
  3401. case "forward":
  3402. case "backward":
  3403. this.editingCommitted(null, event.target.textContent, context.previousContent, context, result);
  3404. break;
  3405. }
  3406.  
  3407. event.consume();
  3408. return;
  3409. }
  3410.  
  3411. if (!isEditingName)
  3412. this._applyFreeFlowStyleTextEdit(false);
  3413. },
  3414.  
  3415. _applyFreeFlowStyleTextEdit: function(now)
  3416. {
  3417. if (this._applyFreeFlowStyleTextEditTimer)
  3418. clearTimeout(this._applyFreeFlowStyleTextEditTimer);
  3419.  
  3420. function apply()
  3421. {
  3422. var valueText = this.valueElement.textContent;
  3423. if (valueText.indexOf(";") === -1)
  3424. this.applyStyleText(this.nameElement.textContent + ": " + valueText, false, false, false);
  3425. }
  3426. if (now)
  3427. apply.call(this);
  3428. else
  3429. this._applyFreeFlowStyleTextEditTimer = setTimeout(apply.bind(this), 100);
  3430. },
  3431.  
  3432. kickFreeFlowStyleEditForTest: function()
  3433. {
  3434. this._applyFreeFlowStyleTextEdit(true);
  3435. },
  3436.  
  3437. editingEnded: function(context)
  3438. {
  3439. this._resetMouseDownElement();
  3440. if (this._applyFreeFlowStyleTextEditTimer)
  3441. clearTimeout(this._applyFreeFlowStyleTextEditTimer);
  3442.  
  3443. this.hasChildren = context.hasChildren;
  3444. if (context.expanded)
  3445. this.expand();
  3446. var editedElement = context.isEditingName ? this.nameElement : this.valueElement;
  3447.  
  3448. if (editedElement.parentElement)
  3449. editedElement.parentElement.removeStyleClass("child-editing");
  3450.  
  3451. delete this._parentPane._isEditingStyle;
  3452. },
  3453.  
  3454. editingCancelled: function(element, context)
  3455. {
  3456. this._removePrompt();
  3457. this._revertStyleUponEditingCanceled(this.originalPropertyText);
  3458.  
  3459. this.editingEnded(context);
  3460. },
  3461.  
  3462. _revertStyleUponEditingCanceled: function(originalPropertyText)
  3463. {
  3464. if (typeof originalPropertyText === "string") {
  3465. delete this.originalPropertyText;
  3466. this.applyStyleText(originalPropertyText, true, false, true);
  3467. } else {
  3468. if (this._newProperty)
  3469. this.treeOutline.removeChild(this);
  3470. else
  3471. this.updateTitle();
  3472. }
  3473. },
  3474.  
  3475. _findSibling: function(moveDirection)
  3476. {
  3477. var target = this;
  3478. do {
  3479. target = (moveDirection === "forward" ? target.nextSibling : target.previousSibling);
  3480. } while(target && target.inherited);
  3481.  
  3482. return target;
  3483. },
  3484.  
  3485. editingCommitted: function(element, userInput, previousContent, context, moveDirection)
  3486. {
  3487. this._removePrompt();
  3488. this.editingEnded(context);
  3489. var isEditingName = context.isEditingName;
  3490.  
  3491.  
  3492. var createNewProperty, moveToPropertyName, moveToSelector;
  3493. var moveTo = this;
  3494. var moveToOther = (isEditingName ^ (moveDirection === "forward"));
  3495. var abandonNewProperty = this._newProperty && !userInput && (moveToOther || isEditingName);
  3496. if (moveDirection === "forward" && !isEditingName || moveDirection === "backward" && isEditingName) {
  3497. moveTo = moveTo._findSibling(moveDirection);
  3498. if (moveTo)
  3499. moveToPropertyName = moveTo.name;
  3500. else if (moveDirection === "forward" && (!this._newProperty || userInput))
  3501. createNewProperty = true;
  3502. else if (moveDirection === "backward")
  3503. moveToSelector = true;
  3504. }
  3505.  
  3506.  
  3507. var moveToIndex = moveTo && this.treeOutline ? this.treeOutline.children.indexOf(moveTo) : -1;
  3508. var blankInput = /^\s*$/.test(userInput);
  3509. var isDataPasted = "originalName" in context;
  3510. var isDirtyViaPaste = isDataPasted && (this.nameElement.textContent !== context.originalName || this.valueElement.textContent !== context.originalValue);
  3511. var shouldCommitNewProperty = this._newProperty && (moveToOther || (!moveDirection && !isEditingName) || (isEditingName && blankInput));
  3512. if (((userInput !== previousContent || isDirtyViaPaste) && !this._newProperty) || shouldCommitNewProperty) {
  3513. this.treeOutline.section._afterUpdate = moveToNextCallback.bind(this, this._newProperty, !blankInput, this.treeOutline.section);
  3514. var propertyText;
  3515. if (blankInput || (this._newProperty && /^\s*$/.test(this.valueElement.textContent)))
  3516. propertyText = "";
  3517. else {
  3518. if (isEditingName)
  3519. propertyText = userInput + ": " + this.valueElement.textContent;
  3520. else
  3521. propertyText = this.nameElement.textContent + ": " + userInput;
  3522. }
  3523. this.applyStyleText(propertyText, true, true, false);
  3524. } else {
  3525. if (!isDataPasted && !this._newProperty)
  3526. this.updateTitle();
  3527. moveToNextCallback.call(this, this._newProperty, false, this.treeOutline.section);
  3528. }
  3529.  
  3530.  
  3531. function moveToNextCallback(alreadyNew, valueChanged, section)
  3532. {
  3533. if (!moveDirection)
  3534. return;
  3535.  
  3536.  
  3537. if (moveTo && moveTo.parent) {
  3538. moveTo.startEditing(!isEditingName ? moveTo.nameElement : moveTo.valueElement);
  3539. return;
  3540. }
  3541.  
  3542.  
  3543.  
  3544. if (moveTo && !moveTo.parent) {
  3545. var propertyElements = section.propertiesTreeOutline.children;
  3546. if (moveDirection === "forward" && blankInput && !isEditingName)
  3547. --moveToIndex;
  3548. if (moveToIndex >= propertyElements.length && !this._newProperty)
  3549. createNewProperty = true;
  3550. else {
  3551. var treeElement = moveToIndex >= 0 ? propertyElements[moveToIndex] : null;
  3552. if (treeElement) {
  3553. var elementToEdit = !isEditingName ? treeElement.nameElement : treeElement.valueElement;
  3554. if (alreadyNew && blankInput)
  3555. elementToEdit = moveDirection === "forward" ? treeElement.nameElement : treeElement.valueElement;
  3556. treeElement.startEditing(elementToEdit);
  3557. return;
  3558. } else if (!alreadyNew)
  3559. moveToSelector = true;
  3560. }
  3561. }
  3562.  
  3563.  
  3564. if (createNewProperty) {
  3565. if (alreadyNew && !valueChanged && (isEditingName ^ (moveDirection === "backward")))
  3566. return;
  3567.  
  3568. section.addNewBlankProperty().startEditing();
  3569. return;
  3570. }
  3571.  
  3572. if (abandonNewProperty) {
  3573. moveTo = this._findSibling(moveDirection);
  3574. var sectionToEdit = (moveTo || moveDirection === "backward") ? section : section.nextEditableSibling();
  3575. if (sectionToEdit) {
  3576. if (sectionToEdit.rule)
  3577. sectionToEdit.startEditingSelector();
  3578. else
  3579. sectionToEdit._moveEditorFromSelector(moveDirection);
  3580. }
  3581. return;
  3582. }
  3583.  
  3584. if (moveToSelector) {
  3585. if (section.rule)
  3586. section.startEditingSelector();
  3587. else
  3588. section._moveEditorFromSelector(moveDirection);
  3589. }
  3590. }
  3591. },
  3592.  
  3593. _removePrompt: function()
  3594. {
  3595.  
  3596. if (this._prompt) {
  3597. this._prompt.detach();
  3598. delete this._prompt;
  3599. }
  3600. },
  3601.  
  3602. _hasBeenModifiedIncrementally: function()
  3603. {
  3604.  
  3605.  
  3606. return typeof this.originalPropertyText === "string" || (!!this.property.propertyText && this._newProperty);
  3607. },
  3608.  
  3609. applyStyleText: function(styleText, updateInterface, majorChange, isRevert)
  3610. {
  3611. function userOperationFinishedCallback(parentPane, updateInterface)
  3612. {
  3613. if (updateInterface)
  3614. delete parentPane._userOperation;
  3615. }
  3616.  
  3617.  
  3618. if (!isRevert && !updateInterface && !this._hasBeenModifiedIncrementally()) {
  3619.  
  3620.  
  3621. this.originalPropertyText = this.property.propertyText;
  3622. }
  3623.  
  3624. if (!this.treeOutline)
  3625. return;
  3626.  
  3627. var section = this.treeOutline.section;
  3628. styleText = styleText.replace(/\s/g, " ").trim(); 
  3629. var styleTextLength = styleText.length;
  3630. if (!styleTextLength && updateInterface && !isRevert && this._newProperty && !this._hasBeenModifiedIncrementally()) {
  3631.  
  3632. this.parent.removeChild(this);
  3633. section.afterUpdate();
  3634. return;
  3635. }
  3636.  
  3637. var currentNode = this._parentPane.node;
  3638. if (updateInterface)
  3639. this._parentPane._userOperation = true;
  3640.  
  3641. function callback(userCallback, originalPropertyText, newStyle)
  3642. {
  3643. if (!newStyle) {
  3644. if (updateInterface) {
  3645.  
  3646. this._revertStyleUponEditingCanceled(originalPropertyText);
  3647. }
  3648. userCallback();
  3649. return;
  3650. }
  3651.  
  3652. if (this._newProperty)
  3653. this._newPropertyInStyle = true;
  3654. this.style = newStyle;
  3655. this.property = newStyle.propertyAt(this.property.index);
  3656. this._styleRule.style = this.style;
  3657.  
  3658. if (section && section.pane)
  3659. section.pane.dispatchEventToListeners("style edited");
  3660.  
  3661. if (updateInterface && currentNode === section.pane.node) {
  3662. this._updatePane(userCallback);
  3663. return;
  3664. }
  3665.  
  3666. userCallback();
  3667. }
  3668.  
  3669.  
  3670.  
  3671. if (styleText.length && !/;\s*$/.test(styleText))
  3672. styleText += ";";
  3673. var overwriteProperty = !!(!this._newProperty || this._newPropertyInStyle);
  3674. this.property.setText(styleText, majorChange, overwriteProperty, callback.bind(this, userOperationFinishedCallback.bind(null, this._parentPane, updateInterface), this.originalPropertyText));
  3675. },
  3676.  
  3677. ondblclick: function()
  3678. {
  3679. return true; 
  3680. },
  3681.  
  3682. isEventWithinDisclosureTriangle: function(event)
  3683. {
  3684. if (!this.section.computedStyle)
  3685. return event.target === this._expandElement;
  3686. return TreeElement.prototype.isEventWithinDisclosureTriangle.call(this, event);
  3687. },
  3688.  
  3689. __proto__: TreeElement.prototype
  3690. }
  3691.  
  3692.  
  3693. WebInspector.StylesSidebarPane.CSSPropertyPrompt = function(cssCompletions, sidebarPane, isEditingName, acceptCallback)
  3694. {
  3695.  
  3696. WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this), WebInspector.StyleValueDelimiters);
  3697. this.setSuggestBoxEnabled("generic-suggest");
  3698. this._cssCompletions = cssCompletions;
  3699. this._sidebarPane = sidebarPane;
  3700. this._isEditingName = isEditingName;
  3701. }
  3702.  
  3703. WebInspector.StylesSidebarPane.CSSPropertyPrompt.prototype = {
  3704. onKeyDown: function(event)
  3705. {
  3706. switch (event.keyIdentifier) {
  3707. case "Up":
  3708. case "Down":
  3709. case "PageUp":
  3710. case "PageDown":
  3711. if (this._handleNameOrValueUpDown(event)) {
  3712. event.preventDefault();
  3713. return;
  3714. }
  3715. break;
  3716. }
  3717.  
  3718. WebInspector.TextPrompt.prototype.onKeyDown.call(this, event);
  3719. },
  3720.  
  3721. onMouseWheel: function(event)
  3722. {
  3723. if (this._handleNameOrValueUpDown(event)) {
  3724. event.consume(true);
  3725. return;
  3726. }
  3727. WebInspector.TextPrompt.prototype.onMouseWheel.call(this, event);
  3728. },
  3729.  
  3730. tabKeyPressed: function()
  3731. {
  3732. this.acceptAutoComplete();
  3733.  
  3734.  
  3735. return false;
  3736. },
  3737.  
  3738. _handleNameOrValueUpDown: function(event)
  3739. {
  3740. function finishHandler(originalValue, replacementString)
  3741. {
  3742.  
  3743. this._sidebarPane.applyStyleText(this._sidebarPane.nameElement.textContent + ": " + this._sidebarPane.valueElement.textContent, false, false, false);
  3744. }
  3745.  
  3746.  
  3747. if (!this._isEditingName && WebInspector.handleElementValueModifications(event, this._sidebarPane.valueElement, finishHandler.bind(this), this._isValueSuggestion.bind(this)))
  3748. return true;
  3749.  
  3750. return false;
  3751. },
  3752.  
  3753. _isValueSuggestion: function(word)
  3754. {
  3755. if (!word)
  3756. return false;
  3757. word = word.toLowerCase();
  3758. return this._cssCompletions.keySet().hasOwnProperty(word);
  3759. },
  3760.  
  3761.  
  3762. _buildPropertyCompletions: function(proxyElement, wordRange, force, completionsReadyCallback)
  3763. {
  3764. var prefix = wordRange.toString().toLowerCase();
  3765. if (!prefix && !force)
  3766. return;
  3767.  
  3768. var results = this._cssCompletions.startsWith(prefix);
  3769. var selectedIndex = this._cssCompletions.mostUsedOf(results);
  3770. completionsReadyCallback(results, selectedIndex);
  3771. },
  3772.  
  3773. __proto__: WebInspector.TextPrompt.prototype
  3774. }
  3775. ;
  3776.  
  3777.  
  3778. WebInspector.ElementsPanel = function()
  3779. {
  3780. WebInspector.Panel.call(this, "elements");
  3781. this.registerRequiredCSS("breadcrumbList.css");
  3782. this.registerRequiredCSS("elementsPanel.css");
  3783. this.registerRequiredCSS("textPrompt.css");
  3784. this.setHideOnDetach();
  3785.  
  3786. const initialSidebarWidth = 325;
  3787. const minimumContentWidthPercent = 34;
  3788. this.createSidebarView(this.element, WebInspector.SidebarView.SidebarPosition.Right, initialSidebarWidth);
  3789. this.splitView.setMinimumSidebarWidth(Preferences.minElementsSidebarWidth);
  3790. this.splitView.setMinimumMainWidthPercent(minimumContentWidthPercent);
  3791.  
  3792. this.contentElement = this.splitView.mainElement;
  3793. this.contentElement.id = "elements-content";
  3794. this.contentElement.addStyleClass("outline-disclosure");
  3795. this.contentElement.addStyleClass("source-code");
  3796. if (!WebInspector.settings.domWordWrap.get())
  3797. this.contentElement.classList.add("nowrap");
  3798. WebInspector.settings.domWordWrap.addChangeListener(this._domWordWrapSettingChanged.bind(this));
  3799.  
  3800. this.contentElement.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
  3801.  
  3802. this.treeOutline = new WebInspector.ElementsTreeOutline(true, true, false, this._populateContextMenu.bind(this), this._setPseudoClassForNodeId.bind(this));
  3803. this.treeOutline.wireToDomAgent();
  3804.  
  3805. this.treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
  3806.  
  3807. this.crumbsElement = document.createElement("div");
  3808. this.crumbsElement.className = "crumbs";
  3809. this.crumbsElement.addEventListener("mousemove", this._mouseMovedInCrumbs.bind(this), false);
  3810. this.crumbsElement.addEventListener("mouseout", this._mouseMovedOutOfCrumbs.bind(this), false);
  3811.  
  3812. this.sidebarPanes = {};
  3813. this.sidebarPanes.computedStyle = new WebInspector.ComputedStyleSidebarPane();
  3814. this.sidebarPanes.styles = new WebInspector.StylesSidebarPane(this.sidebarPanes.computedStyle, this._setPseudoClassForNodeId.bind(this));
  3815. this.sidebarPanes.metrics = new WebInspector.MetricsSidebarPane();
  3816. this.sidebarPanes.properties = new WebInspector.PropertiesSidebarPane();
  3817. this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane;
  3818. this.sidebarPanes.eventListeners = new WebInspector.EventListenersSidebarPane();
  3819.  
  3820. this.sidebarPanes.styles.onexpand = this.updateStyles.bind(this);
  3821. this.sidebarPanes.metrics.onexpand = this.updateMetrics.bind(this);
  3822. this.sidebarPanes.properties.onexpand = this.updateProperties.bind(this);
  3823. this.sidebarPanes.eventListeners.onexpand = this.updateEventListeners.bind(this);
  3824.  
  3825. this.sidebarPanes.styles.expanded = true;
  3826.  
  3827. this.sidebarPanes.styles.addEventListener("style edited", this._stylesPaneEdited, this);
  3828. this.sidebarPanes.styles.addEventListener("style property toggled", this._stylesPaneEdited, this);
  3829. this.sidebarPanes.metrics.addEventListener("metrics edited", this._metricsPaneEdited, this);
  3830.  
  3831. for (var pane in this.sidebarPanes) {
  3832. this.sidebarElement.appendChild(this.sidebarPanes[pane].element);
  3833. if (this.sidebarPanes[pane].onattach)
  3834. this.sidebarPanes[pane].onattach();
  3835. }
  3836.  
  3837. this._registerShortcuts();
  3838.  
  3839. this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this));
  3840. this._popoverHelper.setTimeout(0);
  3841.  
  3842. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._updateBreadcrumbIfNeeded, this);
  3843. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._updateBreadcrumbIfNeeded, this);
  3844. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.NodeRemoved, this._nodeRemoved, this);
  3845. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdatedEvent, this);
  3846. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.InspectElementRequested, this._inspectElementRequested, this);
  3847.  
  3848. if (WebInspector.domAgent.existingDocument())
  3849. this._documentUpdated(WebInspector.domAgent.existingDocument());
  3850. }
  3851.  
  3852. WebInspector.ElementsPanel.prototype = {
  3853. get statusBarItems()
  3854. {
  3855. return [this.crumbsElement];
  3856. },
  3857.  
  3858. defaultFocusedElement: function()
  3859. {
  3860. return this.treeOutline.element;
  3861. },
  3862.  
  3863. statusBarResized: function()
  3864. {
  3865. this.updateBreadcrumbSizes();
  3866. },
  3867.  
  3868. wasShown: function()
  3869. {
  3870.  
  3871. if (this.treeOutline.element.parentElement !== this.contentElement)
  3872. this.contentElement.appendChild(this.treeOutline.element);
  3873.  
  3874. WebInspector.Panel.prototype.wasShown.call(this);
  3875.  
  3876. this.updateBreadcrumb();
  3877. this.treeOutline.updateSelection();
  3878. this.treeOutline.setVisible(true);
  3879.  
  3880. if (!this.treeOutline.rootDOMNode)
  3881. WebInspector.domAgent.requestDocument();
  3882.  
  3883. this.sidebarElement.insertBefore(this.sidebarPanes.domBreakpoints.element, this.sidebarPanes.eventListeners.element);
  3884. },
  3885.  
  3886. willHide: function()
  3887. {
  3888. WebInspector.domAgent.hideDOMNodeHighlight();
  3889. this.treeOutline.setVisible(false);
  3890. this._popoverHelper.hidePopover();
  3891.  
  3892.  
  3893. this.contentElement.removeChild(this.treeOutline.element);
  3894.  
  3895. for (var pane in this.sidebarPanes) {
  3896. if (this.sidebarPanes[pane].willHide)
  3897. this.sidebarPanes[pane].willHide();
  3898. }
  3899.  
  3900. WebInspector.Panel.prototype.willHide.call(this);
  3901. },
  3902.  
  3903. onResize: function()
  3904. {
  3905. this.treeOutline.updateSelection();
  3906. this.updateBreadcrumbSizes();
  3907. },
  3908.  
  3909.  
  3910. _setPseudoClassForNodeId: function(nodeId, pseudoClass, enable)
  3911. {
  3912. var node = WebInspector.domAgent.nodeForId(nodeId);
  3913. if (!node)
  3914. return;
  3915.  
  3916. var pseudoClasses = node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
  3917. if (enable) {
  3918. pseudoClasses = pseudoClasses || [];
  3919. if (pseudoClasses.indexOf(pseudoClass) >= 0)
  3920. return;
  3921. pseudoClasses.push(pseudoClass);
  3922. node.setUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName, pseudoClasses);
  3923. } else {
  3924. if (!pseudoClasses || pseudoClasses.indexOf(pseudoClass) < 0)
  3925. return;
  3926. pseudoClasses.remove(pseudoClass);
  3927. if (!pseudoClasses.length)
  3928. node.removeUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
  3929. }
  3930.  
  3931. this.treeOutline.updateOpenCloseTags(node);
  3932. WebInspector.cssModel.forcePseudoState(node.id, node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName));
  3933. this._metricsPaneEdited();
  3934. this._stylesPaneEdited();
  3935. },
  3936.  
  3937. _selectedNodeChanged: function()
  3938. {
  3939. var selectedNode = this.selectedDOMNode();
  3940. if (!selectedNode && this._lastValidSelectedNode)
  3941. this._selectedPathOnReset = this._lastValidSelectedNode.path();
  3942.  
  3943. this.updateBreadcrumb(false);
  3944.  
  3945. this._updateSidebars();
  3946.  
  3947. if (selectedNode) {
  3948. ConsoleAgent.addInspectedNode(selectedNode.id);
  3949. this._lastValidSelectedNode = selectedNode;
  3950. }
  3951. WebInspector.notifications.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged);
  3952. },
  3953.  
  3954. _updateSidebars: function()
  3955. {
  3956. for (var pane in this.sidebarPanes)
  3957. this.sidebarPanes[pane].needsUpdate = true;
  3958.  
  3959. this.updateStyles(true);
  3960. this.updateMetrics();
  3961. this.updateProperties();
  3962. this.updateEventListeners();
  3963. },
  3964.  
  3965. _reset: function()
  3966. {
  3967. delete this.currentQuery;
  3968. },
  3969.  
  3970. _documentUpdatedEvent: function(event)
  3971. {
  3972. this._documentUpdated(event.data);
  3973. },
  3974.  
  3975. _documentUpdated: function(inspectedRootDocument)
  3976. {
  3977. this._reset();
  3978. this.searchCanceled();
  3979.  
  3980. this.treeOutline.rootDOMNode = inspectedRootDocument;
  3981.  
  3982. if (!inspectedRootDocument) {
  3983. if (this.isShowing())
  3984. WebInspector.domAgent.requestDocument();
  3985. return;
  3986. }
  3987.  
  3988. this.sidebarPanes.domBreakpoints.restoreBreakpoints();
  3989.  
  3990.  
  3991. function selectNode(candidateFocusNode)
  3992. {
  3993. if (!candidateFocusNode)
  3994. candidateFocusNode = inspectedRootDocument.body || inspectedRootDocument.documentElement;
  3995.  
  3996. if (!candidateFocusNode)
  3997. return;
  3998.  
  3999. this.selectDOMNode(candidateFocusNode);
  4000. if (this.treeOutline.selectedTreeElement)
  4001. this.treeOutline.selectedTreeElement.expand();
  4002. }
  4003.  
  4004. function selectLastSelectedNode(nodeId)
  4005. {
  4006. if (this.selectedDOMNode()) {
  4007.  
  4008. return;
  4009. }
  4010. var node = nodeId ? WebInspector.domAgent.nodeForId(nodeId) : null;
  4011. selectNode.call(this, node);
  4012. }
  4013.  
  4014. if (this._selectedPathOnReset)
  4015. WebInspector.domAgent.pushNodeByPathToFrontend(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
  4016. else
  4017. selectNode.call(this);
  4018. delete this._selectedPathOnReset;
  4019. },
  4020.  
  4021. searchCanceled: function()
  4022. {
  4023. delete this._searchQuery;
  4024. this._hideSearchHighlights();
  4025.  
  4026. WebInspector.searchController.updateSearchMatchesCount(0, this);
  4027.  
  4028. delete this._currentSearchResultIndex;
  4029. delete this._searchResults;
  4030. WebInspector.domAgent.cancelSearch();
  4031. },
  4032.  
  4033.  
  4034. performSearch: function(query)
  4035. {
  4036.  
  4037. this.searchCanceled();
  4038.  
  4039. const whitespaceTrimmedQuery = query.trim();
  4040. if (!whitespaceTrimmedQuery.length)
  4041. return;
  4042.  
  4043. this._searchQuery = query;
  4044.  
  4045.  
  4046. function resultCountCallback(resultCount)
  4047. {
  4048. WebInspector.searchController.updateSearchMatchesCount(resultCount, this);
  4049. if (!resultCount)
  4050. return;
  4051.  
  4052. this._searchResults = new Array(resultCount);
  4053. this._currentSearchResultIndex = -1;
  4054. this.jumpToNextSearchResult();
  4055. }
  4056. WebInspector.domAgent.performSearch(whitespaceTrimmedQuery, resultCountCallback.bind(this));
  4057. },
  4058.  
  4059. _contextMenuEventFired: function(event)
  4060. {
  4061. function toggleWordWrap()
  4062. {
  4063. WebInspector.settings.domWordWrap.set(!WebInspector.settings.domWordWrap.get());
  4064. }
  4065.  
  4066. var contextMenu = new WebInspector.ContextMenu(event);
  4067. var populated = this.treeOutline.populateContextMenu(contextMenu, event);
  4068.  
  4069. if (WebInspector.experimentsSettings.cssRegions.isEnabled()) {
  4070. contextMenu.appendSeparator();
  4071. contextMenu.appendItem(WebInspector.UIString("CSS Named Flows..."), this._showNamedFlowCollections.bind(this));
  4072. }
  4073.  
  4074. contextMenu.appendSeparator();
  4075. contextMenu.appendCheckboxItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Word wrap" : "Word Wrap"), toggleWordWrap.bind(this), WebInspector.settings.domWordWrap.get());
  4076.  
  4077. contextMenu.show();
  4078. },
  4079.  
  4080. _showNamedFlowCollections: function()
  4081. {
  4082. if (!WebInspector.cssNamedFlowCollectionsView)
  4083. WebInspector.cssNamedFlowCollectionsView = new WebInspector.CSSNamedFlowCollectionsView();
  4084. WebInspector.cssNamedFlowCollectionsView.showInDrawer();
  4085. },
  4086.  
  4087. _domWordWrapSettingChanged: function(event)
  4088. {
  4089. if (event.data)
  4090. this.contentElement.removeStyleClass("nowrap");
  4091. else
  4092. this.contentElement.addStyleClass("nowrap");
  4093.  
  4094. var selectedNode = this.selectedDOMNode();
  4095. if (!selectedNode)
  4096. return;
  4097.  
  4098. var treeElement = this.treeOutline.findTreeElement(selectedNode);
  4099. if (treeElement)
  4100. treeElement.updateSelection(); 
  4101. },
  4102.  
  4103. switchToAndFocus: function(node)
  4104. {
  4105.  
  4106. WebInspector.searchController.cancelSearch();
  4107. WebInspector.inspectorView.setCurrentPanel(this);
  4108. this.selectDOMNode(node, true);
  4109. },
  4110.  
  4111. _populateContextMenu: function(contextMenu, node)
  4112. {
  4113.  
  4114. contextMenu.appendSeparator();
  4115. var pane = this.sidebarPanes.domBreakpoints;
  4116. pane.populateNodeContextMenu(node, contextMenu);
  4117. },
  4118.  
  4119. _getPopoverAnchor: function(element)
  4120. {
  4121. var anchor = element.enclosingNodeOrSelfWithClass("webkit-html-resource-link");
  4122. if (anchor) {
  4123. if (!anchor.href)
  4124. return null;
  4125.  
  4126. var resource = WebInspector.resourceTreeModel.resourceForURL(anchor.href);
  4127. if (!resource || resource.type !== WebInspector.resourceTypes.Image)
  4128. return null;
  4129.  
  4130. anchor.removeAttribute("title");
  4131. }
  4132. return anchor;
  4133. },
  4134.  
  4135. _loadDimensionsForNode: function(treeElement, callback)
  4136. {
  4137.  
  4138. if (treeElement.treeOutline !== this.treeOutline) {
  4139. callback();
  4140. return;
  4141. }
  4142.  
  4143. var node =   (treeElement.representedObject);
  4144.  
  4145. if (!node.nodeName() || node.nodeName().toLowerCase() !== "img") {
  4146. callback();
  4147. return;
  4148. }
  4149.  
  4150. WebInspector.RemoteObject.resolveNode(node, "", resolvedNode);
  4151.  
  4152. function resolvedNode(object)
  4153. {
  4154. if (!object) {
  4155. callback();
  4156. return;
  4157. }
  4158.  
  4159. object.callFunctionJSON(dimensions, undefined, callback);
  4160. object.release();
  4161.  
  4162. function dimensions()
  4163. {
  4164. return { offsetWidth: this.offsetWidth, offsetHeight: this.offsetHeight, naturalWidth: this.naturalWidth, naturalHeight: this.naturalHeight };
  4165. }
  4166. }
  4167. },
  4168.  
  4169.  
  4170. _showPopover: function(anchor, popover)
  4171. {
  4172. var listItem = anchor.enclosingNodeOrSelfWithNodeName("li");
  4173. if (listItem && listItem.treeElement)
  4174. this._loadDimensionsForNode(listItem.treeElement, WebInspector.DOMPresentationUtils.buildImagePreviewContents.bind(WebInspector.DOMPresentationUtils, anchor.href, true, showPopover));
  4175. else
  4176. WebInspector.DOMPresentationUtils.buildImagePreviewContents(anchor.href, true, showPopover);
  4177.  
  4178.  
  4179. function showPopover(contents)
  4180. {
  4181. if (!contents)
  4182. return;
  4183. popover.setCanShrink(false);
  4184. popover.show(contents, anchor);
  4185. }
  4186. },
  4187.  
  4188. jumpToNextSearchResult: function()
  4189. {
  4190. if (!this._searchResults)
  4191. return;
  4192.  
  4193. this._hideSearchHighlights();
  4194. if (++this._currentSearchResultIndex >= this._searchResults.length)
  4195. this._currentSearchResultIndex = 0;
  4196.  
  4197. this._highlightCurrentSearchResult();
  4198. },
  4199.  
  4200. jumpToPreviousSearchResult: function()
  4201. {
  4202. if (!this._searchResults)
  4203. return;
  4204.  
  4205. this._hideSearchHighlights();
  4206. if (--this._currentSearchResultIndex < 0)
  4207. this._currentSearchResultIndex = (this._searchResults.length - 1);
  4208.  
  4209. this._highlightCurrentSearchResult();
  4210. return true;
  4211. },
  4212.  
  4213. _highlightCurrentSearchResult: function()
  4214. {
  4215. var index = this._currentSearchResultIndex;
  4216. var searchResults = this._searchResults;
  4217. var searchResult = searchResults[index];
  4218.  
  4219. if (searchResult === null) {
  4220. WebInspector.searchController.updateCurrentMatchIndex(index, this);
  4221. return;
  4222. }
  4223.  
  4224. if (typeof searchResult === "undefined") {
  4225.  
  4226. function callback(node)
  4227. {
  4228. searchResults[index] = node || null;
  4229. this._highlightCurrentSearchResult();
  4230. }
  4231. WebInspector.domAgent.searchResult(index, callback.bind(this));
  4232. return;
  4233. }
  4234.  
  4235. WebInspector.searchController.updateCurrentMatchIndex(index, this);
  4236.  
  4237. var treeElement = this.treeOutline.findTreeElement(searchResult);
  4238. if (treeElement) {
  4239. treeElement.highlightSearchResults(this._searchQuery);
  4240. treeElement.reveal();
  4241. }
  4242. },
  4243.  
  4244. _hideSearchHighlights: function()
  4245. {
  4246. if (!this._searchResults)
  4247. return;
  4248. var searchResult = this._searchResults[this._currentSearchResultIndex];
  4249. if (!searchResult)
  4250. return;
  4251. var treeElement = this.treeOutline.findTreeElement(searchResult);
  4252. if (treeElement)
  4253. treeElement.hideSearchHighlights();
  4254. },
  4255.  
  4256. selectedDOMNode: function()
  4257. {
  4258. return this.treeOutline.selectedDOMNode();
  4259. },
  4260.  
  4261.  
  4262. selectDOMNode: function(node, focus)
  4263. {
  4264. this.treeOutline.selectDOMNode(node, focus);
  4265. },
  4266.  
  4267. _nodeRemoved: function(event)
  4268. {
  4269. if (!this.isShowing())
  4270. return;
  4271.  
  4272. var crumbs = this.crumbsElement;
  4273. for (var crumb = crumbs.firstChild; crumb; crumb = crumb.nextSibling) {
  4274. if (crumb.representedObject === event.data.node) {
  4275. this.updateBreadcrumb(true);
  4276. return;
  4277. }
  4278. }
  4279. },
  4280.  
  4281. _stylesPaneEdited: function()
  4282. {
  4283.  
  4284. this.sidebarPanes.metrics.needsUpdate = true;
  4285. this.updateMetrics();
  4286. },
  4287.  
  4288. _metricsPaneEdited: function()
  4289. {
  4290.  
  4291. this.sidebarPanes.styles.needsUpdate = true;
  4292. this.updateStyles(true);
  4293. },
  4294.  
  4295. _mouseMovedInCrumbs: function(event)
  4296. {
  4297. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  4298. var crumbElement = nodeUnderMouse.enclosingNodeOrSelfWithClass("crumb");
  4299.  
  4300. WebInspector.domAgent.highlightDOMNode(crumbElement ? crumbElement.representedObject.id : 0);
  4301.  
  4302. if ("_mouseOutOfCrumbsTimeout" in this) {
  4303. clearTimeout(this._mouseOutOfCrumbsTimeout);
  4304. delete this._mouseOutOfCrumbsTimeout;
  4305. }
  4306. },
  4307.  
  4308. _mouseMovedOutOfCrumbs: function(event)
  4309. {
  4310. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  4311. if (nodeUnderMouse && nodeUnderMouse.isDescendant(this.crumbsElement))
  4312. return;
  4313.  
  4314. WebInspector.domAgent.hideDOMNodeHighlight();
  4315.  
  4316. this._mouseOutOfCrumbsTimeout = setTimeout(this.updateBreadcrumbSizes.bind(this), 1000);
  4317. },
  4318.  
  4319. _updateBreadcrumbIfNeeded: function(event)
  4320. {
  4321. var name = event.data.name;
  4322. if (name !== "class" && name !== "id")
  4323. return;
  4324.  
  4325. var node =   (event.data.node);
  4326. var crumbs = this.crumbsElement;
  4327. var crumb = crumbs.firstChild;
  4328. while (crumb) {
  4329. if (crumb.representedObject === node) {
  4330. this.updateBreadcrumb(true);
  4331. break;
  4332. }
  4333. crumb = crumb.nextSibling;
  4334. }
  4335. },
  4336.  
  4337.  
  4338. updateBreadcrumb: function(forceUpdate)
  4339. {
  4340. if (!this.isShowing())
  4341. return;
  4342.  
  4343. var crumbs = this.crumbsElement;
  4344.  
  4345. var handled = false;
  4346. var crumb = crumbs.firstChild;
  4347. while (crumb) {
  4348. if (crumb.representedObject === this.selectedDOMNode()) {
  4349. crumb.addStyleClass("selected");
  4350. handled = true;
  4351. } else {
  4352. crumb.removeStyleClass("selected");
  4353. }
  4354.  
  4355. crumb = crumb.nextSibling;
  4356. }
  4357.  
  4358. if (handled && !forceUpdate) {
  4359.  
  4360.  
  4361. this.updateBreadcrumbSizes();
  4362. return;
  4363. }
  4364.  
  4365. crumbs.removeChildren();
  4366.  
  4367. var panel = this;
  4368.  
  4369. function selectCrumbFunction(event)
  4370. {
  4371. var crumb = event.currentTarget;
  4372. if (crumb.hasStyleClass("collapsed")) {
  4373.  
  4374. if (crumb === panel.crumbsElement.firstChild) {
  4375.  
  4376.  
  4377. var currentCrumb = crumb;
  4378. while (currentCrumb) {
  4379. var hidden = currentCrumb.hasStyleClass("hidden");
  4380. var collapsed = currentCrumb.hasStyleClass("collapsed");
  4381. if (!hidden && !collapsed)
  4382. break;
  4383. crumb = currentCrumb;
  4384. currentCrumb = currentCrumb.nextSibling;
  4385. }
  4386. }
  4387.  
  4388. panel.updateBreadcrumbSizes(crumb);
  4389. } else
  4390. panel.selectDOMNode(crumb.representedObject, true);
  4391.  
  4392. event.preventDefault();
  4393. }
  4394.  
  4395. for (var current = this.selectedDOMNode(); current; current = current.parentNode) {
  4396. if (current.nodeType() === Node.DOCUMENT_NODE)
  4397. continue;
  4398.  
  4399. crumb = document.createElement("span");
  4400. crumb.className = "crumb";
  4401. crumb.representedObject = current;
  4402. crumb.addEventListener("mousedown", selectCrumbFunction, false);
  4403.  
  4404. var crumbTitle;
  4405. switch (current.nodeType()) {
  4406. case Node.ELEMENT_NODE:
  4407. WebInspector.DOMPresentationUtils.decorateNodeLabel(current, crumb);
  4408. break;
  4409.  
  4410. case Node.TEXT_NODE:
  4411. crumbTitle = WebInspector.UIString("(text)");
  4412. break
  4413.  
  4414. case Node.COMMENT_NODE:
  4415. crumbTitle = "<!-->";
  4416. break;
  4417.  
  4418. case Node.DOCUMENT_TYPE_NODE:
  4419. crumbTitle = "<!DOCTYPE>";
  4420. break;
  4421.  
  4422. default:
  4423. crumbTitle = current.nodeNameInCorrectCase();
  4424. }
  4425.  
  4426. if (!crumb.childNodes.length) {
  4427. var nameElement = document.createElement("span");
  4428. nameElement.textContent = crumbTitle;
  4429. crumb.appendChild(nameElement);
  4430. crumb.title = crumbTitle;
  4431. }
  4432.  
  4433. if (current === this.selectedDOMNode())
  4434. crumb.addStyleClass("selected");
  4435. if (!crumbs.childNodes.length)
  4436. crumb.addStyleClass("end");
  4437.  
  4438. crumbs.appendChild(crumb);
  4439. }
  4440.  
  4441. if (crumbs.hasChildNodes())
  4442. crumbs.lastChild.addStyleClass("start");
  4443.  
  4444. this.updateBreadcrumbSizes();
  4445. },
  4446.  
  4447.  
  4448. updateBreadcrumbSizes: function(focusedCrumb)
  4449. {
  4450. if (!this.isShowing())
  4451. return;
  4452.  
  4453. if (document.body.offsetWidth <= 0) {
  4454.  
  4455.  
  4456. return;
  4457. }
  4458.  
  4459. var crumbs = this.crumbsElement;
  4460. if (!crumbs.childNodes.length || crumbs.offsetWidth <= 0)
  4461. return; 
  4462.  
  4463.  
  4464. var selectedIndex = 0;
  4465. var focusedIndex = 0;
  4466. var selectedCrumb;
  4467.  
  4468. var i = 0;
  4469. var crumb = crumbs.firstChild;
  4470. while (crumb) {
  4471.  
  4472. if (!selectedCrumb && crumb.hasStyleClass("selected")) {
  4473. selectedCrumb = crumb;
  4474. selectedIndex = i;
  4475. }
  4476.  
  4477.  
  4478. if (crumb === focusedCrumb)
  4479. focusedIndex = i;
  4480.  
  4481.  
  4482.  
  4483. if (crumb !== crumbs.lastChild)
  4484. crumb.removeStyleClass("start");
  4485. if (crumb !== crumbs.firstChild)
  4486. crumb.removeStyleClass("end");
  4487.  
  4488. crumb.removeStyleClass("compact");
  4489. crumb.removeStyleClass("collapsed");
  4490. crumb.removeStyleClass("hidden");
  4491.  
  4492. crumb = crumb.nextSibling;
  4493. ++i;
  4494. }
  4495.  
  4496.  
  4497.  
  4498. crumbs.firstChild.addStyleClass("end");
  4499. crumbs.lastChild.addStyleClass("start");
  4500.  
  4501. function crumbsAreSmallerThanContainer()
  4502. {
  4503. var rightPadding = 20;
  4504. var errorWarningElement = document.getElementById("error-warning-count");
  4505. if (!WebInspector.drawer.visible && errorWarningElement)
  4506. rightPadding += errorWarningElement.offsetWidth;
  4507. return ((crumbs.totalOffsetLeft() + crumbs.offsetWidth + rightPadding) < window.innerWidth);
  4508. }
  4509.  
  4510. if (crumbsAreSmallerThanContainer())
  4511. return; 
  4512.  
  4513. var BothSides = 0;
  4514. var AncestorSide = -1;
  4515. var ChildSide = 1;
  4516.  
  4517.  
  4518. function makeCrumbsSmaller(shrinkingFunction, direction, significantCrumb)
  4519. {
  4520. if (!significantCrumb)
  4521. significantCrumb = (focusedCrumb || selectedCrumb);
  4522.  
  4523. if (significantCrumb === selectedCrumb)
  4524. var significantIndex = selectedIndex;
  4525. else if (significantCrumb === focusedCrumb)
  4526. var significantIndex = focusedIndex;
  4527. else {
  4528. var significantIndex = 0;
  4529. for (var i = 0; i < crumbs.childNodes.length; ++i) {
  4530. if (crumbs.childNodes[i] === significantCrumb) {
  4531. significantIndex = i;
  4532. break;
  4533. }
  4534. }
  4535. }
  4536.  
  4537. function shrinkCrumbAtIndex(index)
  4538. {
  4539. var shrinkCrumb = crumbs.childNodes[index];
  4540. if (shrinkCrumb && shrinkCrumb !== significantCrumb)
  4541. shrinkingFunction(shrinkCrumb);
  4542. if (crumbsAreSmallerThanContainer())
  4543. return true; 
  4544. return false;
  4545. }
  4546.  
  4547.  
  4548.  
  4549. if (direction) {
  4550.  
  4551. var index = (direction > 0 ? 0 : crumbs.childNodes.length - 1);
  4552. while (index !== significantIndex) {
  4553. if (shrinkCrumbAtIndex(index))
  4554. return true;
  4555. index += (direction > 0 ? 1 : -1);
  4556. }
  4557. } else {
  4558.  
  4559.  
  4560. var startIndex = 0;
  4561. var endIndex = crumbs.childNodes.length - 1;
  4562. while (startIndex != significantIndex || endIndex != significantIndex) {
  4563. var startDistance = significantIndex - startIndex;
  4564. var endDistance = endIndex - significantIndex;
  4565. if (startDistance >= endDistance)
  4566. var index = startIndex++;
  4567. else
  4568. var index = endIndex--;
  4569. if (shrinkCrumbAtIndex(index))
  4570. return true;
  4571. }
  4572. }
  4573.  
  4574.  
  4575. return false;
  4576. }
  4577.  
  4578. function coalesceCollapsedCrumbs()
  4579. {
  4580. var crumb = crumbs.firstChild;
  4581. var collapsedRun = false;
  4582. var newStartNeeded = false;
  4583. var newEndNeeded = false;
  4584. while (crumb) {
  4585. var hidden = crumb.hasStyleClass("hidden");
  4586. if (!hidden) {
  4587. var collapsed = crumb.hasStyleClass("collapsed");
  4588. if (collapsedRun && collapsed) {
  4589. crumb.addStyleClass("hidden");
  4590. crumb.removeStyleClass("compact");
  4591. crumb.removeStyleClass("collapsed");
  4592.  
  4593. if (crumb.hasStyleClass("start")) {
  4594. crumb.removeStyleClass("start");
  4595. newStartNeeded = true;
  4596. }
  4597.  
  4598. if (crumb.hasStyleClass("end")) {
  4599. crumb.removeStyleClass("end");
  4600. newEndNeeded = true;
  4601. }
  4602.  
  4603. continue;
  4604. }
  4605.  
  4606. collapsedRun = collapsed;
  4607.  
  4608. if (newEndNeeded) {
  4609. newEndNeeded = false;
  4610. crumb.addStyleClass("end");
  4611. }
  4612. } else
  4613. collapsedRun = true;
  4614. crumb = crumb.nextSibling;
  4615. }
  4616.  
  4617. if (newStartNeeded) {
  4618. crumb = crumbs.lastChild;
  4619. while (crumb) {
  4620. if (!crumb.hasStyleClass("hidden")) {
  4621. crumb.addStyleClass("start");
  4622. break;
  4623. }
  4624. crumb = crumb.previousSibling;
  4625. }
  4626. }
  4627. }
  4628.  
  4629. function compact(crumb)
  4630. {
  4631. if (crumb.hasStyleClass("hidden"))
  4632. return;
  4633. crumb.addStyleClass("compact");
  4634. }
  4635.  
  4636. function collapse(crumb, dontCoalesce)
  4637. {
  4638. if (crumb.hasStyleClass("hidden"))
  4639. return;
  4640. crumb.addStyleClass("collapsed");
  4641. crumb.removeStyleClass("compact");
  4642. if (!dontCoalesce)
  4643. coalesceCollapsedCrumbs();
  4644. }
  4645.  
  4646. if (!focusedCrumb) {
  4647.  
  4648.  
  4649.  
  4650.  
  4651. if (makeCrumbsSmaller(compact, ChildSide))
  4652. return;
  4653.  
  4654.  
  4655. if (makeCrumbsSmaller(collapse, ChildSide))
  4656. return;
  4657. }
  4658.  
  4659.  
  4660. if (makeCrumbsSmaller(compact, (focusedCrumb ? BothSides : AncestorSide)))
  4661. return;
  4662.  
  4663.  
  4664. if (makeCrumbsSmaller(collapse, (focusedCrumb ? BothSides : AncestorSide)))
  4665. return;
  4666.  
  4667. if (!selectedCrumb)
  4668. return;
  4669.  
  4670.  
  4671. compact(selectedCrumb);
  4672. if (crumbsAreSmallerThanContainer())
  4673. return;
  4674.  
  4675.  
  4676. collapse(selectedCrumb, true);
  4677. },
  4678.  
  4679. updateStyles: function(forceUpdate)
  4680. {
  4681. var stylesSidebarPane = this.sidebarPanes.styles;
  4682. var computedStylePane = this.sidebarPanes.computedStyle;
  4683. if ((!stylesSidebarPane.expanded && !computedStylePane.expanded) || !stylesSidebarPane.needsUpdate)
  4684. return;
  4685.  
  4686. stylesSidebarPane.update(this.selectedDOMNode(), forceUpdate);
  4687. stylesSidebarPane.needsUpdate = false;
  4688. },
  4689.  
  4690. updateMetrics: function()
  4691. {
  4692. var metricsSidebarPane = this.sidebarPanes.metrics;
  4693. if (!metricsSidebarPane.expanded || !metricsSidebarPane.needsUpdate)
  4694. return;
  4695.  
  4696. metricsSidebarPane.update(this.selectedDOMNode());
  4697. metricsSidebarPane.needsUpdate = false;
  4698. },
  4699.  
  4700. updateProperties: function()
  4701. {
  4702. var propertiesSidebarPane = this.sidebarPanes.properties;
  4703. if (!propertiesSidebarPane.expanded || !propertiesSidebarPane.needsUpdate)
  4704. return;
  4705.  
  4706. propertiesSidebarPane.update(this.selectedDOMNode());
  4707. propertiesSidebarPane.needsUpdate = false;
  4708. },
  4709.  
  4710. updateEventListeners: function()
  4711. {
  4712. var eventListenersSidebarPane = this.sidebarPanes.eventListeners;
  4713. if (!eventListenersSidebarPane.expanded || !eventListenersSidebarPane.needsUpdate)
  4714. return;
  4715.  
  4716. eventListenersSidebarPane.update(this.selectedDOMNode());
  4717. eventListenersSidebarPane.needsUpdate = false;
  4718. },
  4719.  
  4720. _registerShortcuts: function()
  4721. {
  4722. var shortcut = WebInspector.KeyboardShortcut;
  4723. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Elements Panel"));
  4724. var keys = [
  4725. shortcut.shortcutToString(shortcut.Keys.Up),
  4726. shortcut.shortcutToString(shortcut.Keys.Down)
  4727. ];
  4728. section.addRelatedKeys(keys, WebInspector.UIString("Navigate elements"));
  4729.  
  4730. keys = [
  4731. shortcut.shortcutToString(shortcut.Keys.Right),
  4732. shortcut.shortcutToString(shortcut.Keys.Left)
  4733. ];
  4734. section.addRelatedKeys(keys, WebInspector.UIString("Expand/collapse"));
  4735. section.addKey(shortcut.shortcutToString(shortcut.Keys.Enter), WebInspector.UIString("Edit attribute"));
  4736. section.addKey(shortcut.shortcutToString(shortcut.Keys.F2), WebInspector.UIString("Toggle edit as HTML"));
  4737.  
  4738. this.sidebarPanes.styles.registerShortcuts();
  4739. },
  4740.  
  4741. handleShortcut: function(event)
  4742. {
  4743. if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !event.shiftKey && event.keyIdentifier === "U+005A") { 
  4744. WebInspector.domAgent.undo(this._updateSidebars.bind(this));
  4745. event.handled = true;
  4746. return;
  4747. }
  4748.  
  4749. var isRedoKey = WebInspector.isMac() ? event.metaKey && event.shiftKey && event.keyIdentifier === "U+005A" : 
  4750. event.ctrlKey && event.keyIdentifier === "U+0059"; 
  4751. if (isRedoKey) {
  4752. DOMAgent.redo(this._updateSidebars.bind(this));
  4753. event.handled = true;
  4754. return;
  4755. }
  4756.  
  4757. this.treeOutline.handleShortcut(event);
  4758. },
  4759.  
  4760. handleCopyEvent: function(event)
  4761. {
  4762.  
  4763. if (!window.getSelection().isCollapsed)
  4764. return;
  4765. event.clipboardData.clearData();
  4766. event.preventDefault();
  4767. this.selectedDOMNode().copyNode();
  4768. },
  4769.  
  4770. sidebarResized: function(event)
  4771. {
  4772. this.treeOutline.updateSelection();
  4773. },
  4774.  
  4775. _inspectElementRequested: function(event)
  4776. {
  4777. var node = event.data;
  4778. this.revealAndSelectNode(node.id);
  4779. },
  4780.  
  4781. revealAndSelectNode: function(nodeId)
  4782. {
  4783. WebInspector.inspectorView.setCurrentPanel(this);
  4784.  
  4785. var node = WebInspector.domAgent.nodeForId(nodeId);
  4786. if (!node)
  4787. return;
  4788.  
  4789. WebInspector.domAgent.highlightDOMNodeForTwoSeconds(nodeId);
  4790. this.selectDOMNode(node, true);
  4791. },
  4792.  
  4793.  
  4794. appendApplicableItems: function(event, contextMenu, target)
  4795. {
  4796. if (!(target instanceof WebInspector.RemoteObject))
  4797. return;
  4798. var remoteObject =   (target);
  4799. if (remoteObject.subtype !== "node")
  4800. return;
  4801.  
  4802. function selectNode(nodeId)
  4803. {
  4804. if (nodeId)
  4805. WebInspector.domAgent.inspectElement(nodeId);
  4806. }
  4807.  
  4808. function revealElement()
  4809. {
  4810. remoteObject.pushNodeToFrontend(selectNode);
  4811. }
  4812.  
  4813. contextMenu.appendItem(WebInspector.UIString("Reveal in Elements Panel"), revealElement.bind(this));
  4814. },
  4815.  
  4816. __proto__: WebInspector.Panel.prototype
  4817. }
  4818.